当我打电话给它时,它无法正常工作
AlertDialog alertDialog = new AlertDialog.Builder(getBaseContext()).create();
// Setting Dialog Title
alertDialog.setTitle(e.getMessage());
alertDialog.show();
在MainActivity
中,如何让它发挥作用?
堆栈跟踪是:
android.view.WindowManager$BadTokenException: Unable to add window -- token null is not
for an application 03-18 16:38:07.505:
E/AndroidRuntime(13152): at android.view.ViewRootImpl.setView(ViewRootImpl.java:540) 03-18 16:38:07.505:
E/AndroidRuntime(13152): at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:259) –
答案 0 :(得分:2)
如果您在扩展Activity
的课程中,可以使用
AlertDialog alertDialog = new AlertDialog.Builder(this).create();
// Setting Dialog Title
alertDialog.setTitle(e.getMessage());
if(!mActivity.this.isFinishing()) {
alertDialog.show();
}