Skip to content Skip to sidebar Skip to footer

Array Adapter Notifydatasetchanged() Nullpointerexception Android

I am adding a map to a list and then refreshing the array adapter. This was working perfectly earlier, but now that I am using an addItem() method from two different methods, it th

Solution 1:

You need to initialize adapter before you call createNewEditedEntry in onCreate:

OnCreate(){
     adapter = new SimpleAdapter(this, painItems, R.layout.mylistlayout, from, to);
      if(getIntent().getStringExtra("newPainLevel")!= null){
        createNewEditedEntry();    
      }
// ...
}

Otherwise, adapter will be null in addItem called from there (last line of createNewEditedEntry).

Solution 2:

You should also be aware that your call to addItem can fail if your activity was destroyed by Android while you were in the sub-activity. Have a read of my answer to this question to understand what can happen when resources get low.

Post a Comment for "Array Adapter Notifydatasetchanged() Nullpointerexception Android"