私の Android アプリケーションでは、カスタム ダイアログを使用しています。ダイアログを表示しようとすると、エラーが発生します。何が悪いのかわからず、本当に困っています。
これが私のコードです:
protected Dialog onCreateDialog(int id) {
Dialog dialog;
switch(id) {
case 0:
dialog = new Dialog(getApplicationContext());
dialog.setContentView(R.layout.paused);
dialog.setTitle("Game Paused");
dialog.show();
break;
default:
dialog = null;
}
return null;
}
そして、これがダイアログを表示する方法です
showDialog(0);
ちなみに、showDialog(int) は廃止予定とのことです。
Android ログキャット:
> 06-19 18:44:22.399: W/dalvikvm(467): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
06-19 18:44:22.419: E/AndroidRuntime(467): FATAL EXCEPTION: main
06-19 18:44:22.419: E/AndroidRuntime(467): java.lang.IllegalStateException: Could not execute method of the activity
06-19 18:44:22.419: E/AndroidRuntime(467): at android.view.View$1.onClick(View.java:2072)
06-19 18:44:22.419: E/AndroidRuntime(467): at android.view.View.performClick(View.java:2408)
06-19 18:44:22.419: E/AndroidRuntime(467): at android.view.View$PerformClick.run(View.java:8816)
06-19 18:44:22.419: E/AndroidRuntime(467): at android.os.Handler.handleCallback(Handler.java:587)
06-19 18:44:22.419: E/AndroidRuntime(467): at android.os.Handler.dispatchMessage(Handler.java:92)
06-19 18:44:22.419: E/AndroidRuntime(467): at android.os.Looper.loop(Looper.java:123)
06-19 18:44:22.419: E/AndroidRuntime(467): at android.app.ActivityThread.main(ActivityThread.java:4627)
06-19 18:44:22.419: E/AndroidRuntime(467): at java.lang.reflect.Method.invokeNative(Native Method)
06-19 18:44:22.419: E/AndroidRuntime(467): at java.lang.reflect.Method.invoke(Method.java:521)
06-19 18:44:22.419: E/AndroidRuntime(467): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
06-19 18:44:22.419: E/AndroidRuntime(467): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
06-19 18:44:22.419: E/AndroidRuntime(467): at dalvik.system.NativeStart.main(Native Method)
06-19 18:44:22.419: E/AndroidRuntime(467): Caused by: java.lang.reflect.InvocationTargetException
06-19 18:44:22.419: E/AndroidRuntime(467): at com.jlennon.gametest.PlayGameActivity.pause(PlayGameActivity.java:105)
06-19 18:44:22.419: E/AndroidRuntime(467): at java.lang.reflect.Method.invokeNative(Native Method)
06-19 18:44:22.419: E/AndroidRuntime(467): at java.lang.reflect.Method.invoke(Method.java:521)
06-19 18:44:22.419: E/AndroidRuntime(467): at android.view.View$1.onClick(View.java:2067)
06-19 18:44:22.419: E/AndroidRuntime(467): ... 11 more
06-19 18:44:22.419: E/AndroidRuntime(467): Caused by: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
06-19 18:44:22.419: E/AndroidRuntime(467): at android.view.ViewRoot.setView(ViewRoot.java:509)
06-19 18:44:22.419: E/AndroidRuntime(467): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)
06-19 18:44:22.419: E/AndroidRuntime(467): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
06-19 18:44:22.419: E/AndroidRuntime(467): at android.app.Dialog.show(Dialog.java:241)
06-19 18:44:22.419: E/AndroidRuntime(467): at com.jlennon.gametest.PlayGameActivity.onCreateDialog(PlayGameActivity.java:131)
06-19 18:44:22.419: E/AndroidRuntime(467): at android.app.Activity.onCreateDialog(Activity.java:2472)
06-19 18:44:22.419: E/AndroidRuntime(467): at android.app.Activity.createDialog(Activity.java:881)
06-19 18:44:22.419: E/AndroidRuntime(467): at android.app.Activity.showDialog(Activity.java:2547)
06-19 18:44:22.419: E/AndroidRuntime(467): at android.app.Activity.showDialog(Activity.java:2514)
06-19 18:44:22.419: E/AndroidRuntime(467): ... 15 more
よろしくお願いします!