views:

31

answers:

1

Hey,

I've been trying to follow this tutorial on using Google Map View in Android. In the second part, they create an mContext member variable and then pass that into AlertDialog.Builder(mContext), but the constructor that they call to create an instance of an HelloItemizedOverlay doesn't instantiate mContext, so it's just left null as far as I know.

The program doesn't work properly, and throws a NullPointerException as I suspected. How is this supposed to work?

Thanks,
Jengerer

+1  A: 

In the tutorial, step 2 (the onCreate section) they instantiate a HelloItemizedOverlay:

HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(drawable);

But notice that in the HelloItemizedOverlay constructor, it takes a Drawable and Context:

public HelloItemizedOverlay(Drawable defaultMarker, Context context) {
    super(defaultMarker);
    mContext = context;
}

So the fault is with the tutorial. They're instantiating the class without a Context object, making it null. In your onCreate() method, just add this to the constructor.

Snailer
Right, I tried this and it didn't work, but I realized that they also left out the line that initialized the `ArrayList`, which is why it was crashing even with this fix. Thanks!
Jengerer
Ah, I was just focusing on the Context issue, didn't even notice that. Glad I could partially help!
Snailer