NullPointerException Whilst Trying To Add Polyline/marker To A GoogleMap
I have a SupportMapFragment with a GoogleMap object (which I have manipulated already using a GoogleMapOptions) and it is displaying/functioning fine, until I call getMap().addPoly
Solution 1:
If you add the SupportMapFragment to the layout file you don't have to create a new instance manually. You just need to obtain the reference by calling
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
GoogleMap map = mapFragment.getMap();
You are probably getting the NPE because the newly instantiated fragment haven't created the GoogleMap object yet.
Solution 2:
A strange case I found w/ the latest Google Maps V3 is that you have to set the map bounds before you start adding polylines, etc.
Post a Comment for "NullPointerException Whilst Trying To Add Polyline/marker To A GoogleMap"