Pg 645 - Crash on onPostExecute

#1

Hi there, your chapter example works fine but the one I’ve built does not and I can’t work out the difference between my code and yours no matter what!

I get the location fix and the received JSON just fine, but then this happens:

Attempt to invoke virtual method ‘void android.widget.ImageView.setImageBitmap(android.graphics.Bitmap)’ on a null object reference
at com.bignerdranch.android.locatractivity.LocatrFragment$SearchTask.onPostExecute(LocatrFragment.java:173)
at com.bignerdranch.android.locatractivity.LocatrFragment$SearchTask.onPostExecute(LocatrFragment.java:146)

So the line mImageView.setImageBitmap(mBitmap); is crashing for me due to it being a null object, but I can’t see how it is a null object and your chapter example code does exactly the same and runs ok. Maybe something further up my code is wrong? Any ideas? I’ve compared what I can and it looks identical so far.

#2

It looks like your ImageView is null. Are you sure it’s in your layout file? Does your findViewById call work and return an ImageView?