1

我的片段中有这个扩展 ListFragment:

try {
    FileInputStream in = getActivity().getApplicationContext().openFileInput("list");
    ObjectInputStream i = new ObjectInputStream(in);
    myData = (ArrayList<HashMap<String, MessageRecord>>) i.readObject();
    if (myData != null) {
        this.totalmessages = myData.size();
        mySimpleAdapter = new MySimpleAdapter(getActivity().getApplicationContext(),  myData, R.layout.menurow, mStrings, new int [] {R.id.ivDirection, R.id.tvMessage});
        setListAdapter(mySimpleAdapter);
    }
    in.close();
   }

我收到此错误:

Error: Fetch Message List
Error: java.lang.NullPointException
Error: ...FragmentMessages$1.run(FragmentMessages.java:307)

最后一行指向

mySimpleAdapter.notifyDataSetChanged();

请帮忙。

4

1 回答 1

1

notifyDataSetInvalidated()如果数组为空,并且数组不为空,则调用notifyDataSetChanged()

为了更清楚一点,如果您的数据为空并且在 listView 上设置了emptyViewnotifyDataSetInvalidated()则会显示空视图。您收到的错误是因为在调用notifyDataSetChanged()时,适配器试图在没有数据的情况下创建一个 listView 视图,因此无法构造该视图。

于 2012-06-28T10:31:27.130 回答