android.view.WindowManager$BadTokenException: Unable to add window — token null
2013-06-11 01:49
465 查看
错误产生:
private Context mcontext;
@Override
protected void onCreate(Bundle savedInstanceState) {mcontext = getApplicationContext();
System.out.println("mcontext=" + mcontext);
}
private Context mcontext; @Override protected void onCreate(Bundle savedInstanceState) {mcontext = getApplicationContext(); System.out.println("mcontext=" + mcontext); }
private Context mcontext;
@Override
protected void onCreate(Bundle savedInstanceState) {mcontext = getApplicationContext();
System.out.println("mcontext=" + mcontext);
}
private Context mcontext; @Override protected void onCreate(Bundle savedInstanceState) {mcontext = getApplicationContext(); System.out.println("mcontext=" + mcontext); }
导致报这个错是在于new AlertDialog.Builder(mcontext),虽然这里的参数是AlertDialog.Builder(Context context)但我们不能使用getApplicationContext()获得的Context,而必须使用Activity,因为只有一个Activity才能添加一个窗体。
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();
相关文章推荐
- 异常 android.view.WindowManager$BadTokenException: Unable to add window — token null
- android.view.WindowManager$BadTokenException: Unable to add window — token null
- android.view.WindowManager$BadTokenException: Unable to add window — token null
- [ERROR]android.view.WindowManager$BadTokenException: Unable to add window — token null
- android.view.WindowManager$BadTokenException: Unable to add window — token null
- android.view.WindowManager$BadTokenException: Unable to add window — token null
- android.view.WindowManager$BadTokenException: Unable to add window — token null
- android.view.WindowManager$BadTokenException: Unable to add window — token null
- android.view.WindowManager$BadTokenException: Unable to add window — token null
- 试用dialog时碰到android.view.WindowManager$BadTokenException: Unable to add window — token null
- [crash 分析] android.view.WindowManager$BadTokenException: Unable to add window
- 关于android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an app
- android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@4
- android.view.WindowManager$BadTokenException: Unable to add window
- android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProx...
- android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@2
- AlertDialog.Builder发生:android.view.WindowManager$BadTokenException: Unable to add window
- 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
- Caused by: android.view.WindowManager$BadTokenException: Unable to add window android.view.ViewRootI