0

We are using here map android SDK. We don't use layout at all. So we are stock here about how to use it.

First of all, we need to put the map inside a View(or RelativeLayout).

Secondly, when we try to start the map with the following code:

MapFragment map_fragment = null;
//...
map_fragment = new MapFragment();

// how do we add the map_fragment as a "sub-view" of another View/RelativeLayout

map_fragment(new OnEngineInitListener() {
    @Override
    public void  onEngineInitializationCompleted(OnEngineInitListener.Error error) {
       if (error == OnEngineInitListener.Error.NONE) {
           map_fragment.getMapGesture().
                addOnGestureListener(gestureListener);
               // throws errors at this line
       } else {
       }

    //...
    }
}

It throws an error:

ERROR: Cannot initialize Map Fragment,UNKNOWN,Unknown error occurred.,java.lang.NullPointerException: Cannot initialize with a null Context
I:     at com.nokia.maps.ee.a(Preconditions.java:19)
I:     at com.nokia.maps.MapsEngine.b(MapsEngine.java:355)
I:     at com.nokia.maps.MapsEngine.a(MapsEngine.java:343)
I:     at com.here.android.mpa.common.MapEngine.init(MapEngine.java:129)
I:     at com.nokia.maps.br.a(MapFragmentImpl.java:126)
I:     at com.here.android.mpa.mapping.MapFragment.init(MapFragment.java:108)
Russell H.
  • 21
  • 4

1 Answers1

0

It seems you are calling the init code before the application Context is created? The map fragment is a fragment and needs to be added into the fragment manager before it can be used.

An example stack overflow answer to dynamically adding a fragment would be the following link.

Community
  • 1
  • 1
David Leong
  • 1,662
  • 1
  • 11
  • 7