0

I try to open kml file on Google Maps :

KmlLayer layer = new KmlLayer(getMap(), R.raw.community, getContext());
layer.addLayerToMap();

inside :

onMapReady(GoogleMap map)

but I am getting this exception :

java.lang.NullPointerException: Attempt to invoke virtual method

'com.google.android.gms.maps.model.Polygon com.google.android.gms.maps.GoogleMap.addPolygon(com.google.android.gms.maps.model.PolygonOptions)' on a null object reference

Any help please ?

Thanks

GeniDeveloper
  • 361
  • 3
  • 18
  • Please check PolygonOptions object != null – VVB Apr 17 '16 at 07:36
  • There is no PolygonOptions object, I am just trying to parse a kml file with 2 simple code line : KmlLayer layer = new KmlLayer(getMap(), R.raw.community, getContext()); layer.addLayerToMap(); – GeniDeveloper Apr 17 '16 at 09:19
  • Post polygon drawing code – VVB Apr 17 '16 at 10:55
  • @GeniDeveloper, maybe you are have missed some steps importing KML files to your map. Here is some guide by [Google](https://developers.google.com/maps/documentation/android-api/utility/kml#demo-app) and [How to draw a path on a map using kml file](http://stackoverflow.com/questions/3109158/how-to-draw-a-path-on-a-map-using-kml-file/3109723#3109723) for your reference – Mr.Rebot Apr 18 '16 at 09:11
  • I found the solution, I was putting the kml load before the map getting ready. – GeniDeveloper Apr 18 '16 at 10:34

1 Answers1

0

Fragments in activities Change super.onCreate (savedInstanceState) to super.onCreate (null).

  • 1
    Whilst it's good that you are providing an answer, but code snippets should always come with an explanation, thank you! – AT82 Jan 07 '17 at 11:43