DatabaseRenderer: java.lang.NullPointerException: Attempt to invoke virtual method 'java.io.FileInputStream android.app.Application.openFileInput(java.lang.String)' on a null object reference

919 views
Skip to first unread message

l3ah1.d...@gmail.com

unread,
Apr 30, 2018, 4:52:12 PM4/30/18
to mapsforge-dev

i am traing to make an offline map with mapsforge i flowd the example on https://github.com/mapsforge/mapsforge/blob/master/mapsforge-samples-android/src/main/java/org/mapsforge/samples/android/GettingStarted.java    the first time it worked but i tried to add a gps location to that code but the map doesn't apeer now end i get

DatabaseRenderer: java.lang.NullPointerException: Attempt to invoke virtual method 'java.io.FileInputStream android.app.Application.openFileInput(java.lang.String)' on a null object reference


           public class map extends AppCompatActivity {
      
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView
(R.layout.activity_map);


Drawable myLocationMarker = this.getResources().getDrawable(R.drawable.person);


// final MapViewPosition mapViewPosition = this.mapView.getModel().mapViewPosition;

try {


    mapView
= new MapView(this);
    setContentView
(mapView);
              mapView
.setClickable(true);
    mapView
.getMapScaleBar().setVisible(true);
    mapView
.setBuiltInZoomControls(true);

           
TileCache tileCache = AndroidUtil.createTileCache(map.this, "mapcache",
            mapView
.getModel().displayModel.getTileSize(), 1f,
            mapView
.getModel().frameBufferModel.getOverdrawFactor());


   
File file = new File("/sdcard/download/","centre.map");



   
MapDataStore mapDataStore = new MapFile(file);
   
TileRendererLayer tileRendererLayer = new TileRendererLayer(tileCache, mapDataStore,
            mapView
.getModel().mapViewPosition, AndroidGraphicFactory.INSTANCE);
    tileRendererLayer
.setXmlRenderTheme(InternalRenderTheme.DEFAULT);


    mapView
.getLayerManager().getLayers().add(tileRendererLayer);


    mapView
.setZoomLevel((byte) 10);
} catch (Exception e) {

    e
.printStackTrace();
}

}

  
@Override
  
protected void onDestroy() {
       mapView
.destroyAll();
   
AndroidGraphicFactory.clearResourceMemoryCache();
   
super.onDestroy();
    
}
     
}

i don't understand the problem

Emux

unread,
May 1, 2018, 2:57:19 AM5/1/18
to mapsfo...@googlegroups.com
You have multiple setContentView, try following closely the GettingStarted guide (there're missing calls) or modify it properly.

The extra steps to add a location overlay can be found in LocationOverlayMapViewer example at mapsforge-samples-android.

--
Emux

l3ah1.d...@gmail.com

unread,
May 1, 2018, 4:03:19 AM5/1/18
to mapsforge-dev


Le lundi 30 avril 2018 22:52:12 UTC+2, l3ah1.d...@gmail.com a écrit :

thank you very match for your help i fond the cause of the  problem i have forgotten  to put 


 
AndroidGraphicFactory.createInstance(getApplication());
Reply all
Reply to author
Forward
0 new messages