0

Possible Duplicate:
Crash on ListView.removeFooterView(View)

How is it possible to get a null pointer exception when removing an footerview? I checked that both the footerview and listview are not null before calling

myListView.removeFooterView(mFooterView)

This listview does have a multi-list adapter. I also checked the parent of every footer that could have been added and the parent of each one was null.

BTW, where on earth is the getAllFooterViews? hasFooterView(footerView)? methods in the SDK.

PS. I don't think a well written API should ever hide such information.

  FATAL EXCEPTION:  main
  java.lang.NullPointerException
  at android.widget.ListView.removeFooterView(ListView.java:461)
  at com.mypackage.MyActivity.clearAllFooters()

It does not seem to matter which footer. Its really anything I try to remove at this point, any of the four footers that might have been added.

A bit of context, the ListView is not currently visible, does have focus, and the footer is being cleared after the return of an Async call. I have three listviews on the same MyActivity, and this ListView is not currently visible, it does not have the focus, but still a null pointer exception?

I am compiling 4.03 and deploying on android sdk 2.2

I am also checking that footer count is greater than 0.

9
  • 3
    It would be useful to have a stacktrace, to see if the Nullpointer is caused by the API or your code...
    – mschmoock
    Oct 3, 2012 at 21:42
  • why should such a call ever cause an null pointer exception?
    – Code Droid
    Oct 3, 2012 at 21:48
  • 1
    too less information to tell yet. you posted 1 line of code... there are millions of reasons (maybe even inside the API...).
    – mschmoock
    Oct 3, 2012 at 21:49
  • 1
    The code you posted is for adding a footer view, but the exception is on remove footer view. Are you sure the myListView is not null?
    – Spidy
    Oct 3, 2012 at 21:55
  • Sorry its for removeFooterView(footerView).
    – Code Droid
    Oct 3, 2012 at 21:59

3 Answers 3

3

It could be the version of your Android API. This is described very well here: Crash on ListView.removeFooterView(View)

It looks like the Android team may have forgotten to check for NULL in their API. You may be able to fix this in your custome Adapter class.

3
  • This appears to be correct but the error is in FROYO too. And it is also worth noting that the footer count in the list is not 0 so what is the policy for adding footers?
    – Code Droid
    Oct 3, 2012 at 22:15
  • I've never used the headers or footers myself, wish I could help more.
    – Spidy
    Oct 3, 2012 at 22:16
  • 1
    The question linked here is also by Code Droid...
    – Sam
    Oct 3, 2012 at 22:35
1

As you can see the Nullpointer is caused by the API and not Your code. Which doesnt mean that you cant handle it. I bet theres something not good on your view objects.

ListView.java:461

clearly says that its caused inside android API code...

2
  • 3
    I'm not sure this is correct.
    – keyser
    Oct 3, 2012 at 21:57
  • the view object in question does not seem to matter much. Its just the attempt to remove a view at this point in time that seems to be the culprit.
    – Code Droid
    Oct 3, 2012 at 21:58
0

I would bet in one of two things:

  1. Your myListView is not well inflated, i.e., you are pointing to a undefined View ID (very unlikely, because you could have the same problem when a footer/ header is added or when the list adapter was set); or,
  2. My second guess, and the most likely, would be mFooterView is null. Make sure you had inflated the right footer View.

Let me know about your progress.

1
  • I am checking that neither are null. Also I check that footer count is greater than 0
    – Code Droid
    Oct 3, 2012 at 22:06

Not the answer you're looking for? Browse other questions tagged or ask your own question.