-2

i'm working on a project for indoor navigation and need to add a groundOverlay with the floorplan of the building. I've followed the guidelines on the Documentation from Google dev site. But its giving me NullPointerException when i try to add the overlay to the map. Heres my code:

@Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;

    mMap.setIndoorEnabled(true);
    mMap.setOnIndoorStateChangeListener(this);
    mMap.setPadding(0,0,50,0);
    mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(-28.666957, -55.994823), 19));

    //add mapOverlay
    LatLngBounds iffBounds = new LatLngBounds(
            new LatLng(-28.667177,-55.995104),
            new LatLng(-28.667061,-55.994443)
    );
    GroundOverlayOptions iffMap = new GroundOverlayOptions()
            .image(BitmapDescriptorFactory.fromResource(R.raw.piso_1))
            .positionFromBounds(iffBounds);


    mapOverlay = mMap.addGroundOverlay(iffMap);
}

I have tried debbuging the code and i can't see anything wrong, everything is being correctly instantiated, but when it executes the last line

mapOverlay = mMap.addGroundOverlay(iffmap);

My app crashes.

Here's the StackTrace from logCat:

E/AndroidRuntime: FATAL EXCEPTION: main
              Process: br.com.imerljak.vegvisir, PID: 2390
              java.lang.NullPointerException: null reference
                  at maps.w.c.a(Unknown Source)
                  at maps.ad.g$a.<init>(Unknown Source)
                  at maps.ad.g.a(Unknown Source)
                  at maps.ad.w.<init>(Unknown Source)
                  at maps.ad.u.a(Unknown Source)
                  at vo.onTransact(:com.google.android.gms.DynamiteModulesB:182)
                  at android.os.Binder.transact(Binder.java:380)
                  at com.google.android.gms.maps.internal.IGoogleMapDelegate$zza$zza.addGroundOverlay(Unknown Source)
                  at com.google.android.gms.maps.GoogleMap.addGroundOverlay(Unknown Source)
                  at br.com.imerljak.vegvisir.MapsActivity.onMapReady(MapsActivity.java:62)
                  at com.google.android.gms.maps.SupportMapFragment$zza$1.zza(Unknown Source)
                  at com.google.android.gms.maps.internal.zzt$zza.onTransact(Unknown Source)
                  at android.os.Binder.transact(Binder.java:380)
                  at xz.a(:com.google.android.gms.DynamiteModulesB:82)
                  at maps.ad.u$5.run(Unknown Source)
                  at android.os.Handler.handleCallback(Handler.java:739)
                  at android.os.Handler.dispatchMessage(Handler.java:95)
                  at android.os.Looper.loop(Looper.java:135)
                  at android.app.ActivityThread.main(ActivityThread.java:5312)
                  at java.lang.reflect.Method.invoke(Native Method)
                  at java.lang.reflect.Method.invoke(Method.java:372)
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:901)
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:696)

PS: if anyone has any tips that will help me developing this app (like a good API for indoor navigation) i will be grateful :)

Israel Merljak
  • 241
  • 3
  • 9
  • I do not see anything that causes `null` in your code. I think you need to add some more codes. – Enzokie Sep 12 '16 at 02:56
  • @Enzokie i've investigated further and it seems like the problem is my PNG resource. I've changed to another drawable (a random icon, just for testing) and it executed correctly. It is a quite big image, but even after i've resized it to 200x500 and 50Kb still gives me null when trying to load. – Israel Merljak Sep 12 '16 at 20:12

1 Answers1

0

Your mapOverlay instance refence seems not to be initialized correctly...

Chisko
  • 3,092
  • 6
  • 27
  • 45
  • the mapOverlay object is declared as a global field in class. and its initially null, it expects to receive a compatible object from map.AddGroundOverlay(). even if i remove it and ignore the return it crashes with a null pointer. – Israel Merljak Sep 12 '16 at 14:15