NulPointerException at maps.y.p.onResume(Unknown Source) on implementing fragments for OSMDroid
Asked Answered
R

2

0

I am currently trying to transfer my OSMDroid Map Activity into Fragments. It seems that everything has been set correctly but I'm getting this weird NullPointerException which I'm unsure of solving.

02-20 23:59:36.140: E/AndroidRuntime(970): FATAL EXCEPTION: main
02-20 23:59:36.140: E/AndroidRuntime(970): java.lang.NullPointerException
02-20 23:59:36.140: E/AndroidRuntime(970):  at maps.y.p.onResume(Unknown Source)
02-20 23:59:36.140: E/AndroidRuntime(970):  at com.google.android.gms.maps.internal.IMapFragmentDelegate$Stub.onTransact(IMapFragmentDelegate.java:115)
02-20 23:59:36.140: E/AndroidRuntime(970):  at android.os.Binder.transact(Binder.java:297)
02-20 23:59:36.140: E/AndroidRuntime(970):  at com.google.android.gms.maps.internal.IMapFragmentDelegate$a$a.onResume(Unknown Source)
02-20 23:59:36.140: E/AndroidRuntime(970):  at com.google.android.gms.maps.SupportMapFragment$a.onResume(Unknown Source)
02-20 23:59:36.140: E/AndroidRuntime(970):  at com.google.android.gms.internal.d$1.a(Unknown Source)
02-20 23:59:36.140: E/AndroidRuntime(970):  at com.google.android.gms.internal.d.a(Unknown Source)
02-20 23:59:36.140: E/AndroidRuntime(970):  at com.google.android.gms.internal.d.onResume(Unknown Source)
02-20 23:59:36.140: E/AndroidRuntime(970):  at com.google.android.gms.maps.SupportMapFragment.onResume(Unknown Source)
02-20 23:59:36.140: E/AndroidRuntime(970):  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:918)
02-20 23:59:36.140: E/AndroidRuntime(970):  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1083)
02-20 23:59:36.140: E/AndroidRuntime(970):  at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:635)
02-20 23:59:36.140: E/AndroidRuntime(970):  at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1431)
02-20 23:59:36.140: E/AndroidRuntime(970):  at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:420)
02-20 23:59:36.140: E/AndroidRuntime(970):  at android.os.Handler.handleCallback(Handler.java:605)
02-20 23:59:36.140: E/AndroidRuntime(970):  at android.os.Handler.dispatchMessage(Handler.java:92)
02-20 23:59:36.140: E/AndroidRuntime(970):  at android.os.Looper.loop(Looper.java:137)
02-20 23:59:36.140: E/AndroidRuntime(970):  at android.app.ActivityThread.main(ActivityThread.java:4511)
02-20 23:59:36.140: E/AndroidRuntime(970):  at java.lang.reflect.Method.invokeNative(Native Method)
02-20 23:59:36.140: E/AndroidRuntime(970):  at java.lang.reflect.Method.invoke(Method.java:511)
02-20 23:59:36.140: E/AndroidRuntime(970):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:980)
02-20 23:59:36.140: E/AndroidRuntime(970):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:747)
02-20 23:59:36.140: E/AndroidRuntime(970):  at dalvik.system.NativeStart.main(Native Method)
02-20 23:59:36.225: E/android.os.Debug(29093): !@Dumpstate > dumpstate -k -t -n -z -d -o /data/log/dumpstate_app_error

Here are my part of my codes for the fragment class:

public View onCreateView(LayoutInflater inflator, ViewGroup container, Bundle savedInstanceState) {

    final View view = inflator.inflate(R.layout.offline_map_activity, container, false);


    myOpenMapView = (MapView) view.findViewById(R.id.openmapview);

    mResourceProxy = new DefaultResourceProxyImpl(getSherlockActivity().getApplicationContext());
    myOpenMapView.getTileProvider().clearTileCache();

    File aFile = new File(Environment.getExternalStorageDirectory().toString() + 
            "/test/offlineMap/" + tID + ".zip");
    IArchiveFile[] myArchives = new IArchiveFile[1];
    myArchives[0] = ArchiveFileFactory.getArchiveFile(aFile);
    MyTileSource myTiles = new MyTileSource( "" + tID, null, 12, 12, 256, ".png");
    MapTileModuleProviderBase[] myProviders = new MapTileModuleProviderBase[2];
    myProviders[0] = new MapTileFileArchiveProvider(new SimpleRegisterReceiver(getSherlockActivity().getApplicationContext()), 
            myTiles, myArchives);
    myProviders[1] =  new MapTileDownloader(TileSourceFactory.MAPNIK);
    MapTileProviderArray MyTileProvider = new MapTileProviderArray(myTiles,null, myProviders);
    TilesOverlay MyTilesOverlay = new TilesOverlay(MyTileProvider, getSherlockActivity().getApplicationContext());
    //codes continue...


    return view;
}

Do let me know if more of the codes need to be shown. Thanks!

Refusal answered 20/2, 2013 at 16:13 Comment(3)
Try to comment everything but osmdroid mapview out and see if you can run it in a super simple version. Also which version of osmdroid are you using? Thirdly consider using android mapsv2 instead of osmdroid as it runs much better in fragments and now support custom tiles.Rosetta
Ok I will try to run the super simple version first... I'm currently using OSMDRoid v3.0.8 library.... As for google android maps v2, may I know if there's an example on how to use it to do support custom tiles? I can't seem to find any examples either... =XRefusal
I did what you said, but it's still having almost the same error: 02-21 11:47:40.523: E/AndroidRuntime(1971): java.lang.NullPointerException 02-21 11:47:40.523: E/AndroidRuntime(1971): at maps.y.p.onResume(Unknown Source)Refusal
R
0

What I do is create the Osmdroid mapview in code and not xml. You could try to do that instead and then add the view to a container where you want the Osmdroid mapview to reside. This way you'd also be able to test everything more easily.

An example:

    setContentView(R.layout.main);
    RelativeLayout mapContainer = (RelativeLayout)
    findViewById(R.id.osm_map_container);

    final Harbor harbor = getHarbor();

    mMapView = new MapView(this, 256);  // you can supply other parameters here as well.
    LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    mMapView.setLayoutParams(params);
    mapContainer.addView(mMapView);
Rosetta answered 21/2, 2013 at 8:4 Comment(1)
Sorry I'm not very good with handling OSMDroid in codes... how should I be doing that then?Refusal
L
0

I think you may just be missing this, it fixed it in mine that had a similar issue to this.

super.onCreateView(inflater, container, savedInstanceState);
Liuka answered 25/2, 2014 at 17:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.