错误Spinner setOnItemSelectedListener:android.view.WindowManager $ BadTokenException:无法添加窗口 - 令牌null不适用于应用程序

时间:2014-07-06 11:32:54

标签: android listview android-spinner android-ui

在我的应用程序中,我在listview中有一个微调器,下面的代码是我管理微调器的。

在listview适配器的getview()内部

    addSpinnerValue(mList.get(position).getSchedule());// method to set the ArrayAdapter to spinner
    spinnerSchedule.setOnItemSelectedListener(new OnItemSelectedListener() {

            @Override
            public void onItemSelected(AdapterView<?> arg0, View arg1,
                    int arg2, long arg3) {
                Log.w("onCLick","position"+arg2);

            }

            @Override
            public void onNothingSelected(AdapterView<?> arg0) {
                // TODO Auto-generated method stub

            }
        }); 

  //Method which is setting the spinner Adapter(Outside the getview)
  public void addSpinnerValue(String schedule) {
    ArrayAdapter<String> adapter1 = new ArrayAdapter<String>(Activity_ManageListing.this,R.layout.row_spinner, R.id.textView1, spinnerforlist);
    spinnerSchedule.setAdapter(adapter1); 
  }

当微调器点击时,我收到错误:

 07-06 16:44:43.160: E/AndroidRuntime(552): android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
07-06 16:44:43.160: E/AndroidRuntime(552):  at android.view.ViewRoot.setView(ViewRoot.java:509)
07-06 16:44:43.160: E/AndroidRuntime(552):  at android.view.ViewRoot.setView(ViewRoot.java:509)
07-06 16:44:43.160: E/AndroidRuntime(552):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)
07-06 16:44:43.160: E/AndroidRuntime(552):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
07-06 16:44:43.160: E/AndroidRuntime(552):  at android.app.Dialog.show(Dialog.java:241)
07-06 16:44:43.160: E/AndroidRuntime(552):  at android.app.AlertDialog$Builder.show(AlertDialog.java:802)
07-06 16:44:43.160: E/AndroidRuntime(552):  at android.widget.Spinner.performClick(Spinner.java:257)
07-06 16:44:43.160: E/AndroidRuntime(552):  at android.view.View$PerformClick.run(View.java:8816)
07-06 16:44:43.160: E/AndroidRuntime(552):  at android.os.Handler.handleCallback(Handler.java:587)
07-06 16:44:43.160: E/AndroidRuntime(552):  at android.os.Handler.dispatchMessage(Handler.java:92)
07-06 16:44:43.160: E/AndroidRuntime(552):  at android.os.Looper.loop(Looper.java:123)
07-06 16:44:43.160: E/AndroidRuntime(552):  at android.app.ActivityThread.main(ActivityThread.java:4627)
07-06 16:44:43.160: E/AndroidRuntime(552):  at java.lang.reflect.Method.invokeNative(Native Method)
07-06 16:44:43.160: E/AndroidRuntime(552):  at java.lang.reflect.Method.invoke(Method.java:521)
07-06 16:44:43.160: E/AndroidRuntime(552):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-06 16:44:43.160: E/AndroidRuntime(552):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-06 16:44:43.160: E/AndroidRuntime(552):  at dalvik.system.NativeStart.main(Native Method)

整天我试图解决这个问题,但仍然存在。任何人都可以指导解决此问题

先谢谢

编辑: 我的疑问是为什么我得到这个以下错误,而spinner onclick

 07-06 16:44:43.160: E/AndroidRuntime(552):  at android.app.Dialog.show(Dialog.java:241)
 07-06 16:44:43.160: E/AndroidRuntime(552):  at android.app.AlertDialog$Builder.show(AlertDialog.java:802)
 07-06 16:44:43.160: E/AndroidRuntime(552):  at android.widget.Spinner.performClick(Spinner.java:257)
 07-06 16:44:43.160: E/AndroidRuntime(552):  at android.view.View$PerformClick.run(View.java:8816)

0 个答案:

没有答案