I tried to implement the Google Map View tutorial on the Android developer site, but I always have a problem when trying to display AlertDialog when I click on the overlay image. The problem is that mContext is null when called
AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
in the HelloItemizedOverlay onTap method because the constructor
public HelloItemizedOverlay(Drawable defaultMarker, Context context) { super(boundCenterBottom(defaultMarker)); mContext = context; }
never gets called (what can I say) that initializes mContext. When i replace
HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(drawable);
from
HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(drawable, this.getApplicationContext());
in the HelloGoogleMaps onCreate method, to initialize the context, I get an exception
android.view.WindowManager $ BadTokenException: Unable to add window - null token is not for application
when I try to display AlertDialog as follows:
dialog.show();
I assume that this lesson has been successfully implemented by thousands of people, so I'm at a loss why no one else has encountered this problem ... did I miss an important step from the textbook?
source share