打开AlertDialog时为什么我的应用程序强制关闭

时间:2014-09-23 16:43:16

标签: android alertdialog

我的应用程序出错了。我正在尝试使用AlertDialog来显示" Credits"在应用程序中,但当我点击单词"信用"应用程序只是强制关闭,为什么?这是我的代码:

 else if (mMergeAdapter.getAdapter(position).equals(
                    mMenuAdapter)) {
                // handle menu items
                switch ((int) mMergeAdapter.getItemId(position)) {
                    case 0:
                        Intent intent2 = new Intent(Browser.this,
                                SettingsActivity.class);
                        startActivity(intent2);
                        break;
                    case 1:
                        AlertDialog alertDialog = new AlertDialog.Builder(Browser.this).create();
                        alertDialog.setTitle("Credits");
                        alertDialog.setMessage("Coding -> Traabefi ");
                        alertDialog.setIcon(R.drawable.ic_launcher);
                        alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
                                 public void onClick(DialogInterface dialog, int a) { alertDialog.this.cancel();
                        }});
                        alertDialog.show();
                    case 2:
                        finish();

logcat的

09-23 18:48:02.606 30963 30963 D dalvikvm com.tproductions.Openit延迟启用CheckJNI 09-23 18:48:02.806 30963 30963 W ResourceType com.tproductions.Openit创建80字节的字符串缓存 09-23 18:48:02.936 30963 30963 I Adreno-EGL com.tproductions.Openit:EGL 1.4 QUALCOMM build :() 09-23 18:48:02.936 30963 30963 I Adreno-EGL com.tproductions.Openit OpenGL ES Shader编译器版本:E031.24.00.07 09-23 18:48:02.936 30963 30963 I Adreno-EGL com.tproductions.Openit Build Date:04/07/14 Mon 09-23 18:48:02.936 30963 30963 I Adreno-EGL com.tproductions.Openit Local Branch:au011 09-23 18:48:02.936 30963 30963 I Adreno-EGL com.tproductions.Openit Remote Branch: 09-23 18:48:02.936 30963 30963 I Adreno-EGL com.tproductions.Openit Local Patches: 09-23 18:48:02.936 30963 30963 I Adreno-EGL com.tproductions.Openit Reconstruct Branch: 09-23 18:48:02.966 30963 30963 D OpenGLRenderer com.tproductions.Openit启用调试模式0 09-23 18:48:03.356 30963 30963 I ActivityManager com.tproductions.Openit Timeline:Activity_idle id:android.os.BinderProxy@42dd99e8 time:88828979 09-23 18:48:09.346 30963 30963 E WindowManager com.tproductions.Openit
09-23 18:48:09.346 30963 30963 E WindowManager com.tproductions.Openit android.view.WindowLeaked:Activity com.tproductions.Openit.Browser泄露了窗口com.android.internal.policy.impl.PhoneWindow $ DecorView {4300d1a8 VE .... R ..... ID 0,0-684,662}最初在这里添加 09-23 18:48:09.346 30963 30963 E WindowManager com.tproductions.Openit at android.view.ViewRootImpl。(ViewRootImpl.java:350) 09-23 18:48:09.346 30963 30963 E WindowManager com.tproductions.Openit at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:248) 09-23 18:48:09.346 30963 30963 E WindowManager com.tproductions.Openit at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69) 09-23 18:48:09.346 30963 30963 E WindowManager com.tproductions.Openit at android.app.Dialog.show(Dialog.java:294) 09-23 18:48:09.346 30963 30963 E WindowManager com.tproductions.Openit at com.tproductions.Openit.Browser $ 100000003.onItemClick(Browser.java:340) 09-23 18:48:09.346 30963 30963 E WindowManager com.tproductions.Openit at android.widget.AdapterView.performItemClick(AdapterView.java:299) 09-23 18:48:09.346 30963 30963 E WindowManager com.tproductions.Openit at android.widget.AbsListView.performItemClick(AbsListView.java:1113) 09-23 18:48:09.346 30963 30963 E WindowManager com.tproductions.Openit at android.widget.AbsListView $ PerformClick.run(AbsListView.java:2911) 09-23 18:48:09.346 30963 30963 E WindowManager com.tproductions.Openit at android.widget.AbsListView $ 3.run(AbsListView.java:3645) 09-23 18:48:09.346 30963 30963 E WindowManager com.tproductions.Openit at android.os.Handler.handleCallback(Handler.java:733) 09-23 18:48:09.346 30963 30963 E WindowManager com.tproductions.Openit at android.os.Handler.dispatchMessage(Handler.java:95) 09-23 18:48:09.346 30963 30963 E WindowManager com.tproductions.Openit at android.os.Looper.loop(Looper.java:212) 09-23 18:48:09.346 30963 30963 E WindowManager com.tproductions.Openit at android.app.ActivityThread.main(ActivityThread.java:5135) 09-23 18:48:09.346 30963 30963 E WindowManager com.tproductions.Openit at java.lang.reflect.Method.invokeNative(Native Method) 09-23 18:48:09.346 30963 30963 E WindowManager com.tproductions.Openit at java.lang.reflect.Method.invoke(Method.java:515) 09-23 18:48:09.346 30963 30963 E WindowManager com.tproductions.Openit at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:877) 09-23 18:48:09.346 30963 30963 E WindowManager com.tproductions.Openit at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693) 09-23 18:48:09.346 30963 30963 E WindowManager com.tproductions.Openit at dalvik.system.NativeStart.main(Native Method)

2 个答案:

答案 0 :(得分:2)

break;之后放置alertDialog.show();发生错误,因为活动正在被销毁,但对话框的内存仍然被占用。

答案 1 :(得分:1)

确保休息一下;在你调用alertDialog.show();

之后

这将阻止您进入案例2并完成您认为不打算做的活动。