android spinner点击android.view.WindowManager$BadTokenException: Unable to add window token is not va
2013-07-09 15:25
441 查看
当主界面是一个TabActivity,其中底部有4个ActivityGroup,然后在ActivityGroup跳转到另外一个Activity上面使用Spinner。处理过这个问题的人,都应该知道,Spinner可以显示,但是点击Spinner之后,就会报错。。。信息如下:android.view.WindowManager$BadTokenException: Unable to add window -- token android.app.LocalActivityManager$LocalActivityRecord@44f1f3a8 is not valid; is your activity running?但是百度之后,基本没有解决的方法。。。之后在google之后,终于到了解决方案:在Activity的oncreate()方法里面:把this.setContentView(R.layout.XXXXX);修改为:
在把
ArrayAdapter<CharSequence> spinneraAdapter = ArrayAdapter.createFromResource(getParent(), R.array.wishclassfiy,android.R.layout.simple_spinner_item);修改为:
ArrayAdapter<CharSequence> spinneraAdapter = ArrayAdapter.createFromResource(this , R.array.wishclassfiy,android.R.layout.simple_spinner_item);这样就可以解决Spinner 的android.view.WindowManager$BadTokenException: Unable to add windowd的错误 原博客地址:http://aijiawang-126-com.javaeye.com/blog/662336在Activity中newSpinner是我把mContext传入,但是出了android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application这个错误,参考了达人的文章终于搞定。view plaincopyto clipboardprint?private Context mcontext; @Override protected void onCreate(Bundle savedInstanceState) {mcontext = getApplicationContext(); System.out.println("mcontext=" + mcontext); } view plaincopyto 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 plaincopyto 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();
相关文章推荐
- android spinner点击android.view.WindowManager$BadTokenException: Unable to add window token is not va
- 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 is not valid; is yo
- Caused by: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
- 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 is not for an appli
- 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 is not valid
- 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 for an appli
- android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an appl
- 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 is not for an appli
- 关于android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an app
- setview android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for
- 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 is not for an appli
- 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 is not for an appli
- android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an appli