Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android.view.WindowManager$Badtoken自定义对话框异常_Android_Exception_Window Managers_Customdialog - Fatal编程技术网

android.view.WindowManager$Badtoken自定义对话框异常

android.view.WindowManager$Badtoken自定义对话框异常,android,exception,window-managers,customdialog,Android,Exception,Window Managers,Customdialog,我的应用程序在特定的android版本和设备(VIVO搭载android 5.1和Oneplus搭载android 7.1)上崩溃,并出现以下错误堆栈 QuickMath.java中的代码片段如下 final Dialog customDialog = new Dialog(**this**); customDialog.setContentView(R.layout.custom_dialog_layout); waitTimer.cancel(); // Cancelling the C

我的应用程序在特定的android版本和设备(VIVO搭载android 5.1和Oneplus搭载android 7.1)上崩溃,并出现以下错误堆栈

QuickMath.java中的代码片段如下

final Dialog customDialog = new Dialog(**this**);
customDialog.setContentView(R.layout.custom_dialog_layout);

waitTimer.cancel();  // Cancelling the CountDownTimer before calling the show custom dialog

customDialog.show();
我怀疑customDialog的初始化。我把上下文用作“this”对吗

android.view.WindowManager$BadTokenException:

你应该调用
你的活动。这是
而不是
这是

不要

final Dialog customDialog = new Dialog(this);
Do

final Dialog customDialog = new Dialog(QuickMath.this);

如果您在click listener中显示对话框,那么您需要使用活动。如果没有,它应该可以正常工作。非常感谢@TrickySolutions。有效。请接受我对延迟回复的真诚道歉。我对堆栈溢出还是个新手。我不确定记号在哪里。在做出建议的更改后,同样的问题再次出现在新设备上。有什么需要帮忙的吗?有人能解释一下为什么会这样吗?
这个
类。这个
有什么区别?@AlexanderAgeychenko
final Dialog customDialog = new Dialog(QuickMath.this);