AlertDialog does not show and causes crash
<p>I'm having a problem displaying an <code>AlertDialog</code> from within the <code>onOptionsItemSelected</code> method. That is, I want the user to press the delete options button and then confirm the deletion before clearing the item from the db. If I run my current code my program crash. Hope someone can help. Much appreciated :)</p>

<p>Here's a code snippet of what I have</p>

<pre><code>    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
      getMenuInflater().inflate(R.menu.detailsmenu, menu);
      return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
      // Handle item selection
      switch(item.getItemId()) {
      case R.id.rename:
        openRenameDialog();
        return true;
      case R.id.delete:         
        openDeleteDialog();
        return true;
      default:
        return super.onOptionsItemSelected(item);   
      }
    }

    private void openDeleteDialog() {
      AlertDialog.Builder alert = new AlertDialog.Builder(this);
      alert.setTitle(R.string.deleteTitle);
      alert.setMessage(R.string.deleteMessage);

      alert.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
          // todo       
        }
      });

      alert.setNegativeButton("No", new DialogInterface.OnClickListener() {
         public void onClick(DialogInterface dialog, int whichButton) { 
            dialog.cancel();
         }
      });

    alert.show();
}
</code></pre>

<p>Logcat output:</p>

<pre>
07-17 14:16:57.845: WARN/KeyCharacterMap(2304): No keyboard for id 0
07-17 14:16:57.845: WARN/KeyCharacterMap(2304): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
07-17 14:17:01.564: WARN/ResourceType(2304): getEntry failing because entryIndex 24 is beyond type entryCount 24
07-17 14:17:01.564: WARN/ResourceType(2304): Failure getting entry for 0x7f040018 (t=3 e=24) in package 0 (error -2147483647)
07-17 14:17:01.564: DEBUG/AndroidRuntime(2304): Shutting down VM
07-17 14:17:01.574: WARN/dalvikvm(2304): threadid=1: thread exiting with uncaught exception (group=0x40015560)
07-17 14:17:01.594: ERROR/AndroidRuntime(2304): FATAL EXCEPTION: main
07-17 14:17:01.594: ERROR/AndroidRuntime(2304): android.content.res.Resources$NotFoundException: String resource ID #0x7f040018
07-17 14:17:01.594: ERROR/AndroidRuntime(2304):     at android.content.res.Resources.getText(Resources.java:201)
07-17 14:17:01.594: ERROR/AndroidRuntime(2304):     at android.content.Context.getText(Context.java:173)
07-17 14:17:01.594: ERROR/AndroidRuntime(2304):     at android.app.AlertDialog$Builder.setMessage(AlertDialog.java:318)
07-17 14:17:01.594: ERROR/AndroidRuntime(2304):     at tod.dosetracker.DetailsActivity.openDeleteDialog(DetailsActivity.java:63)
07-17 14:17:01.594: ERROR/AndroidRuntime(2304):     at tod.dosetracker.DetailsActivity.onOptionsItemSelected(DetailsActivity.java:48)
07-17 14:17:01.594: ERROR/AndroidRuntime(2304):     at android.app.Activity.onMenuItemSelected(Activity.java:2205)
07-17 14:17:01.594: ERROR/AndroidRuntime(2304):     at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:748)
07-17 14:17:01.594: ERROR/AndroidRuntime(2304):     at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:143)
07-17 14:17:01.594: ERROR/AndroidRuntime(2304):     at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:855)
07-17 14:17:01.594: ERROR/AndroidRuntime(2304):     at com.android.internal.view.menu.IconMenuView.invokeItem(IconMenuView.java:532)
07-17 14:17:01.594: ERROR/AndroidRuntime(2304):     at com.android.internal.view.menu.IconMenuItemView.performClick(IconMenuItemView.java:122)
07-17 14:17:01.594: ERROR/AndroidRuntime(2304):     at android.view.View$PerformClick.run(View.java:9080)
07-17 14:17:01.594: ERROR/AndroidRuntime(2304):     at android.os.Handler.handleCallback(Handler.java:587)
07-17 14:17:01.594: ERROR/AndroidRuntime(2304):     at android.os.Handler.dispatchMessage(Handler.java:92)
07-17 14:17:01.594: ERROR/AndroidRuntime(2304):     at android.os.Looper.loop(Looper.java:123)
07-17 14:17:01.594: ERROR/AndroidRuntime(2304):     at android.app.ActivityThread.main(ActivityThread.java:3683)
07-17 14:17:01.594: ERROR/AndroidRuntime(2304):     at java.lang.reflect.Method.invokeNative(Native Method)
07-17 14:17:01.594: ERROR/AndroidRuntime(2304):     at java.lang.reflect.Method.invoke(Method.java:507)
07-17 14:17:01.594: ERROR/AndroidRuntime(2304):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
07-17 14:17:01.594: ERROR/AndroidRuntime(2304):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
07-17 14:17:01.594: ERROR/AndroidRuntime(2304):     at dalvik.system.NativeStart.main(Native Method)
07-17 14:17:01.604: WARN/ActivityManager(60):   Force finishing activity tod.dosetracker/.DetailsActivity
07-17 14:17:02.114: WARN/ActivityManager(60): Activity pause timeout for HistoryRecord{407e38f0 tod.dosetracker/.DetailsActivity}
07-17 14:17:11.615: WARN/ActivityManager(60): Launch timeout has expired, giving up wake lock!
07-17 14:17:12.156: WARN/ActivityManager(60): Activity idle timeout for HistoryRecord{406dbd10 tod.dosetracker/.FoodListActivity}
07-17 14:17:17.388: WARN/ActivityManager(60): Activity destroy timeout for HistoryRecord{407e38f0 tod.dosetracker/.DetailsActivity}
</pre>
