【问题标题】:NullPointerException on asynctask with adapter带有适配器的异步任务上的 NullPointerException
【发布时间】:2012-12-15 17:13:05
【问题描述】:

我正在使用带有适配器的 asy 任务并收到此错误

 java.lang.NullPointerException

问题线是

 listAdapter = new listAdpterRss(this.context, R.layout.listitems,RssArrays,RssArrays.rtl);

我的 asy 任务是这样的

protected void onPostExecute(String result) {
        Dialog.dismiss();
        ListView lv = getListView();
    //  lv.setTextFilterEnabled(true);
        listAdapter = new listAdpterRss(this.context, R.layout.listitems,RssArrays,RssArrays.rtl);
        lv.setAdapter(listAdapter); // on test
        listAdapter.notifyDataSetChanged();
        lv.setOnItemClickListener(new OnItemClickListener() 
        {
            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {
                Intent intent = new Intent(RssItem.this,openRssItem.WebActivity.class);
                intent.putExtra("url", RssArrays.PodcastURL[position].toString());

                startActivity(intent);
                //new splash(ListRss.this,mHandler,listValue.get(position).toString()).execute();
            } 

        });

【问题讨论】:

  • 调试异常是在我拿到listAdapterRss的承包商之前

标签: android-asynctask adapter


【解决方案1】:

您稍后会设置适配器,并且可能会在您的 doInBackground 方法中使用。这就是它显示 nullPointer 的原因。 请把所有这些放在onPreExecute()上:

ListView lv = getListView(); // lv.setTextFilterEnabled(true); listAdapter = new listAdpterRss(this.context, R.layout.listitems,RssArrays,RssArrays.rtl); lv.setAdapter(listAdapter);

然后试试你的代码。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多