I'm trying to load .map file which is placed in /assets folder in android studio. The .map file was downloaded from mapsforge @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);
map = (MapView) findViewById(R.id.map); map.setBuiltInZoomControls(true); map.setTileSource(TileSourceFactory.MAPNIK); IMapController controller = map.getController(); GeoPoint point = new GeoPoint(41.2585, 69.2097); controller.animateTo(point); controller.setZoom(10); File f = new File("file:///android_asset/" + "myfile.map"); if (f.exists()) { File[] list = f.listFiles(); if (list != null) { for (int i = 0; i < list.length; i++) { if (list[i].isDirectory()) { continue; } String name = list[i].getName().toLowerCase(); if (!name.contains(".")) { continue; //skip files without an extension } name = name.substring(name.lastIndexOf(".") + 1); if (name.length() == 0) { continue; } if (ArchiveFileFactory.isFileExtensionRegistered(name)) { try { OfflineTileProvider tileProvider = new OfflineTileProvider(new SimpleRegisterReceiver(this), new File[]{list[i]}); map.setTileProvider(tileProvider); String source = ""; IArchiveFile[] archives = tileProvider.getArchives(); if (archives.length > 0) { Set<String> tileSources = archives[0].getTileSources(); if (!tileSources.isEmpty()) { source = tileSources.iterator().next(); map.setTileSource(FileBasedTileSource.getSource(source)); } else map.setTileSource(TileSourceFactory.DEFAULT_TILE_SOURCE); } else map.setTileSource(TileSourceFactory.DEFAULT_TILE_SOURCE); map.invalidate(); return; } catch (Exception ex) { ex.printStackTrace(); } } } } Toast.makeText(this, f.getAbsolutePath() + " did not have any files I can open! Try using MOBAC", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(this, f.getAbsolutePath() + " dir not found!", Toast.LENGTH_SHORT).show(); } } Getting error "myfileDirectory" did not found.
File f = new File("file:///android_asset/" + "myfile.map");. That does not work as the File class cannot handle files from assets. Google for how to read a file from assets.if (f.exists()) { File[] list = f.listFiles();. Iffis your .map file then how can you think you could list files? You are not trying to load that file as you stated but treating it as a directory instead.