- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
您好,我正在尝试从菜单项调用函数。但我得到了这个异常(exception)。 android.view.WindowManager$BadTokenException:无法添加窗口 - token null 不适用于应用程序
这是我的代码..
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.layout.menu1, menu);
return true;
}
@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
switch(item.getItemId())
{
case R.id.write :
writeToTag();
return true;
case R.id.exit :
exitApplication();
return true;
default :
return super.onMenuItemSelected(featureId, item);
}
}
private void exitApplication() {
AlertDialog.Builder alertDialog = new AlertDialog.Builder(getApplicationContext());
alertDialog.setMessage("Do You Want To Exit..?")
.setPositiveButton("Yes",new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
NFCTagWriterActivity.this.finish();
}
}).setNegativeButton("No",new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
onStart();
}
}).show();
AlertDialog alert = alertDialog.create();
}
最佳答案
您无法使用应用程序上下文创建 AlertDialog。您需要使用 Activity 上下文。对于您的情况,这
是合适的。
关于java - 菜单抛出异常 - android.view.WindowManager$BadTokenException : Unable to add window -- token null is not for an application,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12511725/
我有一个建立异步连接的 Activity ,如下所示: new Thread(new Runnable() { public void run() {
我在 Android 应用程序上有一个 Activity ,该 Activity 启动与我的服务器的同步进程。此过程消耗大量内存和处理,需要一些时间才能完成。 该过程完成后,将向用户显示一个 Aler
自从转移到 androidx 后开始在 Android 7.1 上出现 BadTokenException。它应该是 7.1 中 Toast 的一个已知错误 link但我不太确定,因为它是在我转向 a
我正在尝试在 API 25 中运行我的应用程序,但是当我点击按钮时出现此错误: E/ACRA: ACRA caught a BadTokenException for com.safa.visit.t
当我运行我的代码时,我得到这个错误: : E/InputEventReceiver(1363): Exception dispatching input event. : E/MessageQ
我正在尝试将进度对话框放在 ListView 的 Click 事件上,如下面的代码所述,但出现错误“WindowManager$BadTokenException:无法添加窗口—— token and
我已经在 Android 市场上发布了一个应用程序。我已经在 HTC 和三星上测试过,它工作正常。但是今天我的应用程序出现了如下错误。 android.view.WindowManager$BadTo
我正在读取 GPS 信息并每 10 秒将其发送到网络。 我正在做的是使用运行我的服务类 GPSTracker 的处理程序 public void startGpsService() {
我已经针对同一问题查找了几个帖子,但似乎无法解决我的问题。我在整个应用程序中都使用了微调器,它们运行良好。当我尝试在弹出窗口中使用微调器时,选择它时出现错误。弹出窗口用于添加引用,我已经声明了一个全局
我正在开发一个包含多个 Activity 和服务的 Android 应用程序。一些 Activity 是在我导入到我的项目中的第 3 方库中定义的,问题是在某些设备上(特别是在三星 Galaxy Ta
我正在开发用于背景视频录制 的应用程序,这就是我使用 WindowManager 的原因,但它对我不起作用。出现以下错误: 08-23 15:38:21.021: E/AndroidRuntime(4
如果我直接在oCreate()中添加showPopupWindow();,会报错: android.view.WindowManager$BadTokenException: Unable to ad
我正在使用 Tabwidget,Tab 的实现方式与 tutorial 中所示的方式相同 “MainActivity -> Activity1 -> Activity2(给定图像)” 现在点击微调器给
我创建了一个显示按钮列表的 PopupWindow。最初,对于我列表中的每个项目,我实现了一个 OnLongClickListener 以在 View 持有者中显示一个 Toast 消息: priva
android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@4
我试图在单击按钮后显示 DatePickerDialog,但是一旦单击按钮,它就会停止应用程序并引发以下异常: 05-06 08:46:00.688 18786-18786/carloscoronad
首先,我很清楚发生此错误是因为我试图通过不是Activity 的Context 调用窗口/对话框。 但是没有任何解决方案。我的要求是;我在普通 JAVA 类的方法中有一个带有自定义样式表的 Dialo
当我的应用程序正在运行时,出现此错误: android.view.WindowManager$BadTokenException: Unable to add window -- token null
我正在尝试创建一个覆盖窗口,但是当我尝试将 View 添加到 WindowManager 时,出现异常。我添加了“SYSTEM_ALERT_WINDOW”权限,并在应用信息中启用了“在其他应用上绘制”
我进行了大量搜索以找到答案,但仍然不知道我做错了什么。我只是尝试将 AutoCompleteTextView 与动态数组适配器一起使用。但它对我不起作用:( 我的 OnCreate 方法如下所示: i
我是一名优秀的程序员,十分优秀!