当用户单击按钮时,我正在获取数据库表内容并将其显示在对话框界面中,该界面具有用于显示名称的复选框。问题是当我单击按钮时出现“停止工作”错误。
这是代码:
protected String[] Friends;
protected void showSelectFriendsDialog() {
SQLiteDatabase db = playerDB.getReadableDatabase();
String[] Friend = {"player_name"};
Cursor cursor = db.query(DBHelper.DATABASE_TABLE_NAME_USERINFO, Friend, null, null, null, null, null);
if(cursor != null) {
startManagingCursor(cursor);
while (cursor.moveToNext()) {
String name = cursor.getString(0);
for(int i = 0; i < cursor.getCount(); i++) {
Friends[i] = name;
}
}
}
boolean[] checkedFriends = new boolean[Friends.length];
int count = Friends.length;
for(int i = 0; i < count; i++)
checkedFriends[i] = selectedFriends.contains(Friends[i]);
DialogInterface.OnMultiChoiceClickListener coloursDialogListener = new DialogInterface.OnMultiChoiceClickListener() {
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
if(isChecked)
selectedFriends.add(Friends[which]);
else
selectedFriends.remove(Friends[which]);
}
};
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Select Friends");
builder.setMultiChoiceItems(Friends, checkedFriends, coloursDialogListener);
AlertDialog dialog = builder.create();
dialog.show();
}
这是日志猫:
01-07 12:17:50.770: E/AndroidRuntime(848): FATAL EXCEPTION: main
01-07 12:17:50.770: E/AndroidRuntime(848): java.lang.NullPointerException
01-07 12:17:50.770: E/AndroidRuntime(848): at apk.game.mindwords.Play.showSelectFriendsDialog(Play.java:235)
01-07 12:17:50.770: E/AndroidRuntime(848): at apk.game.mindwords.Play.onClick(Play.java:191)
01-07 12:17:50.770: E/AndroidRuntime(848): at android.view.View.performClick(View.java:4084)
01-07 12:17:50.770: E/AndroidRuntime(848): at android.view.View$PerformClick.run(View.java:16966)
01-07 12:17:50.770: E/AndroidRuntime(848): at android.os.Handler.handleCallback(Handler.java:615)
01-07 12:17:50.770: E/AndroidRuntime(848): at android.os.Handler.dispatchMessage(Handler.java:92)
01-07 12:17:50.770: E/AndroidRuntime(848): at android.os.Looper.loop(Looper.java:137)
01-07 12:17:50.770: E/AndroidRuntime(848): at android.app.ActivityThread.main(ActivityThread.java:4745)
01-07 12:17:50.770: E/AndroidRuntime(848): at java.lang.reflect.Method.invokeNative(Native Method)
01-07 12:17:50.770: E/AndroidRuntime(848): at java.lang.reflect.Method.invoke(Method.java:511)
01-07 12:17:50.770: E/AndroidRuntime(848): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
01-07 12:17:50.770: E/AndroidRuntime(848): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
01-07 12:17:50.770: E/AndroidRuntime(848): at dalvik.system.NativeStart.main(Native Method)