【问题标题】:Exception in ListPopupWindow in AndroidAndroid 中 ListPopupWindow 中的异常
【发布时间】:2016-01-20 22:00:22
【问题描述】:

这是我展示 ListPopupWindow 的一段代码

listPopupWindow = new ListPopupWindow(this); 
        listPopupWindow.setAnchorView(this.findViewById(android.R.id.content)); 

        final String[]messages = new String[MsgFromApp.getMessages().length];

        final ListAdapter adapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, messages); 
        final AdapterView.OnItemClickListener itemClickListener = new AdapterView.OnItemClickListener() { 
            @Override 
            public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) { 
                listPopupWindow.dismiss(); 
                listPopupWindow = null;
            } 
        };
        listPopupWindow.setModal(true);     listPopupWindow.setListSelector(getResources().getDrawable(R.drawable.message)); 
        listPopupWindow.setAdapter(adapter); 
        listPopupWindow.setOnItemClickListener(itemClickListener); 
        listPopupWindow.show();

它给出了以下异常: 引起:android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid;您的活动正在进行吗?

这有什么问题?以及如何解决这个问题?

【问题讨论】:

  • 问题出在listPopupWindow = new ListPopupWindow(this); 这行“this”指的是什么?是否在活动中?

标签: android


【解决方案1】:

当应用程序试图通过打开对话框从后台线程 (AsyncTask) 通知用户时,会发生此异常。 检查此链接:https://stackoverflow.com/a/18665887/4848308

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-11-29
    • 2013-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多