NullPointerException when there is nothing to fetch.
NikolaDespotoski opened this issue · 2 comments
How can you reproduce? When there is nothing to fetch, if you perform a click on the listview header, NPE occurs. I've solved it by adding "if(mOnItemClickListener != null && mState!=State.REFRESHING)". So the item click listener will not be consumed.
The mOnItemClickListener (see point [1] below) is not null but it throws NPE because the arguments of the listener are null, because the event is not performed on any of the child items.
In class:
private class PTROnItemClickListener implements OnItemClickListener{
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
mHasResetHeader = false;
if(mOnItemClickListener != null && mState!=State.REFRESHING){
mOnItemClickListener.onItemClick(adapterView, view, position, id); /// [1]
}
}
}
Looking forward your feedback. Cheers!
Great, thanks! Will include in next merge. Thanks for sharing the fix.
I'm sorry, I don't seem to understand the problem. I've attached the following code to the sampleproject onCreate():
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Log.d("PTR-erikw", "" + adapterView); // Result: eu.erikw.PullToRefreshListView@41335778
Log.d("PTR-erikw", "" + view); // Result: android.widget.LinearLayout@41337f18
Log.d("PTR-erikw", "" + i); // Result: 0
Log.d("PTR-erikw", "" + l); // Result: -1
}
});
Even when I remove all the items from the adapter, none of these items are null and no crash occurs when clicking the header. Can you provide me with a more complete sample? Are you on the master branch or development branch? What commit?
Thanks for your help.
Erik