Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullPointerException when there is nothing to fetch. #7

Closed
NikolaDespotoski opened this issue Apr 22, 2012 · 2 comments
Closed

NullPointerException when there is nothing to fetch. #7

NikolaDespotoski opened this issue Apr 22, 2012 · 2 comments
Assignees

Comments

@NikolaDespotoski
Copy link

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!

@ghost ghost assigned erikwt Apr 22, 2012
@erikwt
Copy link
Owner

erikwt commented Apr 22, 2012

Great, thanks! Will include in next merge. Thanks for sharing the fix.

@erikwt
Copy link
Owner

erikwt commented Apr 23, 2012

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

@erikwt erikwt closed this as completed Jul 10, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants