Skip to content Skip to sidebar Skip to footer

Android: Findviewbyid Gives Me Wrong Pointer?

In my updateGUI() function I update each TextView like so: ((TextView) findViewById(R.id.lbTrackerLat)).setText(String.valueOf(lat)); ((TextView) findViewById(R.id.lbTrackerLong)).

Solution 1:

I am guessing that locationListener is an anonymous inner class of an Activity, which means that it holds a reference to its parent class. So now if this locationListener is not recreated after the onCreate() call, it will reference the old Activity, and a call to findViewById() will return objects hold by that old Activity. Not only will this cause your program to perform incorrectly, but causing memory leaks as well (basically everything created by the original Activity will be retained).

If the above is not the cause, then I'll need more information regarding locationListener and how it is used in order to help.

Post a Comment for "Android: Findviewbyid Gives Me Wrong Pointer?"