android.view.WindowManager$BadTokenException
2013-07-07 08:36
316 查看
1、android.view.WindowManager$BadTokenException: Unable to add window -- token nul
在Activity中newSpinner是我把mContext传入,但是出了android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application这个错误,参考了达人的文章终于搞定。view plaincopy
to clipboardprint?
private Context mcontext;
@Override
protected void onCreate(Bundle savedInstanceState) {mcontext = getApplicationContext();
System.out.println("mcontext=" + mcontext);
}
view plaincopy
to clipboardprint?
new AlertDialog.Builder(mcontext)
.setIcon(android.R.drawable.ic_dialog_alert)
.setTitle("Warnning")
.setMessage(
"You forget to write the message. Do you want to fill out it ??")
.setPositiveButton("Yes", positiveListener).setNegativeButton(
"No", negativeListener).create().show();
导致报这个错是在于new AlertDialog.Builder(mcontext),虽然这里的参数是AlertDialog.Builder(Context context)但我们不能使用getApplicationContext()获得的Context,而必须使用Activity,因为只有一个Activity才能添加一个窗体。
解决方法:将new AlertDialog.Builder(Context context)中的参数用Activity.this(Activity是你的Activity的名称)来填充就可以正确的创建一个Dialog了。
view plaincopy
to clipboardprint?
new AlertDialog.Builder(MyActivity.this)
.setIcon(android.R.drawable.ic_dialog_alert)
.setTitle("Warnning")
.setMessage(
"You forget to write the message. Do you want to fill out it ??")
.setPositiveButton("Yes", positiveListener).setNegativeButton(
"No", negativeListener).create().show();
2、token null is not valid; is your activity running?
popuwindows使用时出现异常:
android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running?
解决方法:
应把pop.showAtLocation(parent, Gravity.TOP,0, 0)这一句移出oncreate方法,在控件渲染完毕后再使用
相关文章推荐
- 异常 android.view.WindowManager$BadTokenException: Unable to add window — token null
- android spinner点击android.view.WindowManager$BadTokenException: Unable to add window token is not va
- android.view.WindowManager$BadTokenException:is your actvity runing?
- android.view.WindowManager$BadTokenException: Unable to add window — token null
- AlertDialog-----android.view.WindowManager$BadTokenException: Unable to add window
- android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is yo
- android.view.WindowManager$BadTokenException: Unable to add window(转)
- 【已解决】android.view.WindowManager$BadTokenException: Unable to add window
- 解决android.view.WindowManager$BadTokenException: Unable to add window -- token android.app.LocalActiv
- 解决android.view.WindowManager$BadTokenException: Unable to add window -- token .
- android.view.WindowManager$BadTokenException: Unable to add window
- android.view.WindowManager$BadTokenException: Unable to add window — token null
- 兔子--android.view.windowmanager BadTokenException :unable to add window token null is not for applica
- 解决: android.view.WindowManager BadTokenException:Unable to add Window.Is your activity running?
- android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an appli
- android.view.WindowManager$BadTokenException:Unable to add window --token is not valid; is your acti
- android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid
- android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an appli
- android.view.WindowManager$BadTokenException: Unable to add window — token null
- android.view.WindowManager$BadTokenException