我正在为 Android 中的财务打印机做一些小诊断项目。因此,在打印时,可能会出现问题(缺纸等)。在这种情况下,我想启动一个 AlertDialog 通知存在问题并询问用户是否要继续打印。
我想制作一个显示在前面的 AlertDialog,而不管当前被带到前面的活动。
我尝试了使用 GetAplicationContext() 方法启动 AlertDialog 的常用方法,但它崩溃得很厉害。
这是堆栈跟踪:
05-11 17:36:56.162: W/dalvikvm(5458): threadid=3: thread exiting with uncaught exception (group=0x4001e390)
05-11 17:36:56.162: E/AndroidRuntime(5458): Uncaught handler: thread main exiting due to uncaught exception
05-11 17:36:56.182: E/AndroidRuntime(5458): java.lang.NullPointerException
05-11 17:36:56.182: E/AndroidRuntime(5458): at android.content.ContextWrapper.getApplicationContext(ContextWrapper.java:100)
05-11 17:36:56.182: E/AndroidRuntime(5458): at bg.barcodes.mobile.routes.java.BaseActivity.onCreateDialog(BaseActivity.java:21)
05-11 17:36:56.182: E/AndroidRuntime(5458): at bg.barcodes.mobile.routes.java.DatecsPrinter.Send(DatecsPrinter.java:319)
05-11 17:36:56.182: E/AndroidRuntime(5458): at bg.barcodes.mobile.routes.java.DatecsPrinter.sendText(DatecsPrinter.java:381)
05-11 17:36:56.182: E/AndroidRuntime(5458): at bg.barcodes.mobile.routes.java.StatusDatecsPrinter.doCommand(StatusDatecsPrinter.java:134)
05-11 17:36:56.182: E/AndroidRuntime(5458): at bg.barcodes.mobile.routes.java.StatusDatecsPrinter.access$0(StatusDatecsPrinter.java:118)
05-11 17:36:56.182: E/AndroidRuntime(5458): at bg.barcodes.mobile.routes.java.StatusDatecsPrinter$1.onClick(StatusDatecsPrinter.java:61)
05-11 17:36:56.182: E/AndroidRuntime(5458): at android.view.View.performClick(View.java:2364)
05-11 17:36:56.182: E/AndroidRuntime(5458): at android.view.View.onTouchEvent(View.java:4179)
05-11 17:36:56.182: E/AndroidRuntime(5458): at android.widget.TextView.onTouchEvent(TextView.java:6650)
05-11 17:36:56.182: E/AndroidRuntime(5458): at android.view.View.dispatchTouchEvent(View.java:3709)
05-11 17:36:56.182: E/AndroidRuntime(5458): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:924)
05-11 17:36:56.182: E/AndroidRuntime(5458): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:924)
05-11 17:36:56.182: E/AndroidRuntime(5458): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:924)
05-11 17:36:56.182: E/AndroidRuntime(5458): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:924)
05-11 17:36:56.182: E/AndroidRuntime(5458): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1695)
05-11 17:36:56.182: E/AndroidRuntime(5458): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1116)
05-11 17:36:56.182: E/AndroidRuntime(5458): at android.app.Activity.dispatchTouchEvent(Activity.java:2068)
05-11 17:36:56.182: E/AndroidRuntime(5458): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1679)
05-11 17:36:56.182: E/AndroidRuntime(5458): at android.view.ViewRoot.handleMessage(ViewRoot.java:1708)
05-11 17:36:56.182: E/AndroidRuntime(5458): at android.os.Handler.dispatchMessage(Handler.java:99)
05-11 17:36:56.182: E/AndroidRuntime(5458): at android.os.Looper.loop(Looper.java:123)
05-11 17:36:56.182: E/AndroidRuntime(5458): at android.app.ActivityThread.main(ActivityThread.java:4595)
05-11 17:36:56.182: E/AndroidRuntime(5458): at java.lang.reflect.Method.invokeNative(Native Method)
05-11 17:36:56.182: E/AndroidRuntime(5458): at java.lang.reflect.Method.invoke(Method.java:521)
05-11 17:36:56.182: E/AndroidRuntime(5458): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
05-11 17:36:56.182: E/AndroidRuntime(5458): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
05-11 17:36:56.182: E/AndroidRuntime(5458): at dalvik.system.NativeStart.main(Native Method)
05-11 17:36:56.192: I/dalvikvm(5458): threadid=7: reacting to signal 3
05-11 17:36:56.222: I/dalvikvm(5458): Wrote stack trace to '/data/anr/traces.txt'
有任何想法吗 ?