老问题:“为什么创建 Toast 会使我的应用程序崩溃?”
如果我不使用 toast,我的应用程序运行良好,但如果我想创建并显示一个简单的 Toast,如下所示:
Toast SimpleToast = Toast.makeText(getApplicationContext(), "Just a toast.",Toast.LENGTH_LONG);
SimpleToast.setGravity(Gravity.TOP, 0, 0);
SimpleToast.show();
我在日志中得到这些行,然后应用程序崩溃:
NotificationService enqueueToast pkg=games.MyAppName callback=android.app.ITransientNotification$Stub$Proxy@49603368 duration=1
ResourceType No package identifier when getting name for resource number 0x00000000
AndroidRuntime Shutting down VM
dalvikvm threadid=3: thread exiting with uncaught exception (group=0x4001b188)
AndroidRuntime Uncaught handler: thread main exiting due to uncaught exception
AndroidRuntime java.lang.NullPointerException
我已经检查并仔细检查了上面的代码是什么导致它崩溃。我正在模拟器上运行,因为我目前没有安卓手机。