0

There is a similar question on SO but i reckon my problem lies elsewhere or I'm missing something rather fundamental here.

I do have a unique ID set for my dialog : static final int DAYS_DIALOG_ID = 1;

I also have a class member variable : private TextView textViewSelectDayOfWeek;

In my overriden method onCreate(), i have :

textViewSelectDayOfWeek = (TextView) findViewById(R.id.textViewSelectDayOfWeek);
textViewSelectDayOfWeek.setOnClickListener(this);

So basically, i caputre my TextView defined in XML file in a variable and i set it's listener.

In my onClick(view v), there's a switch with the following case that is supposed to handle clicks on the TextView that is supposed to handle opening my dialog (do note that the aforementioned switch uses v.getId()):

case R.id.textViewSelectDayOfWeek:
            showDialog(DAYS_DIALOG_ID);
            break;

My overriden method onCreateDialog(int id) also contains a switch statement that uses the ID provided. The case that handles this particular problem-causing dialog is the following:

case DAYS_DIALOG_ID:
            final CharSequence[] daysOfWeek = { "@string/stringMonday"}; // 7 days, skimming unimportant stuff
            return new AlertDialog.Builder(this)
            .setTitle("@string/stringSelectDayDialogTitle")
            .setMultiChoiceItems(daysOfWeek,
                                    new boolean[] {true, true, true, true, true}, // Sets first 5 days as checked by default
                                    new DialogInterface.OnMultiChoiceClickListener() {
                                                        public void onClick(DialogInterface dialog, int day, boolean isChecked) {
                                                            Toast.makeText(getApplicationContext(), daysOfWeek[day], Toast.LENGTH_SHORT).show();
                                                        }
                                   })
                                   .create();

Now, if i click on the TextView with ID textViewSelectDayOfWeek, my app crashes.

I tried Toasting a message in onClick() right before i call showDialog(DAYS_DIALOG_ID) and the message does NOT appear before my app crashes.

What can i do to fix this problem ? I believe i mentioned all the important bits of my code but feel encouraged to request anything that might help.

Thanks in advance.

3
  • What is the error when it crashes? Jan 1, 2012 at 21:29
  • @coder_For_Life22 I've been trying to launch it on my phone (2.2 Android Platform), the usual " has stopped unexpectedly ". Jan 1, 2012 at 21:35
  • If your phone is connected to your development machine, in ddms --logcat you will see exception message. That stack trace would be realy helpful.
    – kosa
    Jan 1, 2012 at 21:54

1 Answer 1

0

I certainly hope this helps someone.

As thinksteep mentioned, the exception thrown is actually fairly useful :)

I had an array of 7 week days and i supplied an incomplete array containing only 5 boolean values, which were to define whether the day is checked or unchecked by default, thinking the remaining values would be initialized with a default value of some kind.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.