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

[亡魂溺海] 提交于 2019-12-02 11:48:48

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);

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);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!