1

When user clicks the button, I am fetching the database table content and displaying it in the Dialog Interface which is having check boxes for displaying names.The problem is when i click the button it "Stopped working" error.

Here is the code:

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();
}

Here is the logcat:

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)
2
  • Can you please post the logcat? Commented Jan 7, 2013 at 12:09
  • Guys I Found out the answer.This post helped me a lot stackoverflow.com/questions/9004077/… Commented Jan 7, 2013 at 13:03

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.