1

I have this in my Fragment extends 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();
   }

I am getting this errors:

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

This last line is pointing to

mySimpleAdapter.notifyDataSetChanged();

Please help.

1 Answers1

1

call notifyDataSetInvalidated() if the array is empty, and notifyDataSetChanged() if the array is not empty.

To clarify a bit more, in case your data is empty and have set an emptyView on the listView, notifyDataSetInvalidated() will bring up the empty view. The error you are getting is because upon calling notifyDataSetChanged(), the adapter is trying to conjure a listView view while there is no data, so therefore can't construct that view.

MrJre
  • 7,082
  • 7
  • 53
  • 66