我在onPostExecute中所做的一切都是NullPointer

时间:2012-11-22 06:14:53

标签: android android-asynctask expandablelistview

我必须从服务器更新expandableList,我使用asyncTask下载并填充本地数据库中的新值,一切都在doInBackground中完成但是在完成之后我尝试在onPostExecute中刷新我的expandableList但是我得到一个nullPointer在加载新数据之前运行正常的声明。我所做的只是调用相同的方法,首先将expandableList放在一边..

首次初始化列表的方法:

public void initializeExpandableList() {
        // TODO Auto-generated method stub
        getValuesForList();
        setupList();
        setupClickListenersOnExpandList();

    }

getValuesForList()setUpList()的代码是:

public void getValuesForList() {

    // get which list_id are present in subtopic table

    DataBaseHelper myDbHelper = new DataBaseHelper(context);
    ArrayList<String> ids = myDbHelper.getListIdsFromSubTopic();

    ArrayList<String> typeList = myDbHelper.getTypeListFromDB(ids);
    // typeList = myDbHelper.getTypeListFromDB();
    Log.v("typelist", typeList + "");
    arrGroupelements = typeList.toArray(new String[typeList.size()]);

    Log.v("arrGrp", arrGroupelements.toString() + "");

    ArrayList<ArrayList<String>> subtopics = myDbHelper.getChildForGroup();

    arrChildelements = new String[subtopics.size()][];
    for (int i = 0; i < subtopics.size(); i++) {
        ArrayList<String> row = subtopics.get(i);
        arrChildelements[i] = row.toArray(new String[row.size()]);
    }
    Log.e("arrChildElements", arrChildelements.toString());

}

对于setUpList()方法:

public void setupList() {
            expList.setAdapter(adap);
            // adap.notifyDataSetChanged();
            ((BaseAdapter) expList.getAdapter()).notifyDataSetChanged();
        }

在doInBackground()中插入数据后,在onPostExecute中我调用了一个方法refresh(),它再次调用initializeExpandableList(),我得到空指针。

private void refresh() {
        // TODO Auto-generated method stub
initializeExpandableList();
    }

而不是initializeExpandableLIst,也尝试了

((BaseAdapter) expList.getAdapter()).notifyDataSetChanged();

并尝试重新启动活动:

Intent intent = getIntent();
         finish();
         startActivity(intent);

再次在最后一行startActivity(intent);

中获取空指针

我在这里想念的是什么?

0 个答案:

没有答案