I received this error while trying to open a dialog from my Android activity. A Google search did not provide any helpful interpretations. Hoping someone has some idea what this exception even means?
08-21 00:42:48.515: ERROR/AndroidRuntime(880): Uncaught handler: thread main exiting due to uncaught exception
08-21 00:42:48.595: ERROR/AndroidRuntime(880): android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
08-21 00:42:48.595: ERROR/AndroidRuntime(880): at android.view.ViewRoot.setView(ViewRoot.java:429)
08-21 00:42:48.595: ERROR/AndroidRuntime(880): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:178)
08-21 00:42:48.595: ERROR/AndroidRuntime(880): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
08-21 00:42:48.595: ERROR/AndroidRuntime(880): at android.app.Dialog.show(Dialog.java:231)
08-21 00:42:48.595: ERROR/AndroidRuntime(880): at android.app.Activity.showDialog(Activity.java:2407)
08-21 00:42:48.595: ERROR/AndroidRuntime(880): at net.sosiouxme.WhenDidI.custom.AlarmEditActivity.openNewAlarmDialog(AlarmEditActivity.java:179)
08-21 00:42:48.595: ERROR/AndroidRuntime(880): at net.sosiouxme.WhenDidI.custom.AlarmEditActivity.onOptionsItemSelected(AlarmEditActivity.java:188)
08-21 00:42:48.595: ERROR/AndroidRuntime(880): at net.sosiouxme.WhenDidI.activity.TrackerEdit.onOptionsItemSelected(TrackerEdit.java:146)
08-21 00:42:48.595: ERROR/AndroidRuntime(880): at android.app.Activity.onMenuItemSelected(Activity.java:2085)
08-21 00:42:48.595: ERROR/AndroidRuntime(880): at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:820)
08-21 00:42:48.595: ERROR/AndroidRuntime(880): at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:139)
08-21 00:42:48.595: ERROR/AndroidRuntime(880): at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:813)
08-21 00:42:48.595: ERROR/AndroidRuntime(880): at com.android.internal.view.menu.IconMenuView.invokeItem(IconMenuView.java:519)
08-21 00:42:48.595: ERROR/AndroidRuntime(880): at com.android.internal.view.menu.IconMenuItemView.performClick(IconMenuItemView.java:122)
08-21 00:42:48.595: ERROR/AndroidRuntime(880): at android.view.View.onTouchEvent(View.java:3828)
08-21 00:42:48.595: ERROR/AndroidRuntime(880): at android.widget.TextView.onTouchEvent(TextView.java:6291)
08-21 00:42:48.595: ERROR/AndroidRuntime(880): at android.view.View.dispatchTouchEvent(View.java:3368)
08-21 00:42:48.595: ERROR/AndroidRuntime(880): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:863)
08-21 00:42:48.595: ERROR/AndroidRuntime(880): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:863)
08-21 00:42:48.595: ERROR/AndroidRuntime(880): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1691)
08-21 00:42:48.595: ERROR/AndroidRuntime(880): at android.view.ViewRoot.handleMessage(ViewRoot.java:1525)
08-21 00:42:48.595: ERROR/AndroidRuntime(880): at android.os.Handler.dispatchMessage(Handler.java:99)`
It might be helpful in the above to know that TrackerEdit inherits from AlarmEditActivity. TrackerEdit has an OptionsMenu, and when I choose an option from that menu it attempts to bring up a dialog via openDialog. The stack trace seems to indicate that it crashes before ever getting a chance to create the dialog. Any help would be appreciated.
EDIT - yes, alright, some code might be pretty helpful, though I thought it might be pretty clear that my classes were the part that started with net.sosiouxme and received onOptionsItemSelected and called Activity.showDialog(). But OK, here are those bits from AlarmEditActivity:
/* ***************************** event handling *************************** */
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.new_alarm:
openNewAlarmDialog();
break;
}
return super.onOptionsItemSelected(item);
}
/*
* Open dialog for user to create a new alarm
*/
public void openNewAlarmDialog() {
Alarm alarm = new Alarm(mTracker.getId());
alarm.setIvalWeeks(1);
mAlarmToEdit = alarm;
mViewOfAlarmToEdit = null;
showDialog(ALARM_DIALOG); // which is 0
}
The code isn't doing anything terribly interesting. When the menu item is chosen, it tries to show a dialog. The code never got to the point where a dialog was to be created, so I haven't even had the chance to mess that up. About the only thing that's remotely interesting about the activity is that the real activity is TrackerEdit which extends AlarmEditActivity, so the code being executed is in the parent of the activity.