我正在尝试从Mapsforge运行“一个非常基本的 Android 应用程序示例”
我正在使用 Eclipse。Android SDK 工具高于版本 19。
我做了以下事情:我下载了 jar 文件并将它们放在 libs/ 文件夹中
- mapsforge-core-0.5.0.jar
- mapsforge-map-0.5.0.jar
- mapsforge-map-android-0.5.0.jar
我的项目编译得很好,但是当它运行时我得到了 NoClassDefFoundError。我一直在寻找答案。我已经尝试将 jars 添加到构建路径并尝试遵循建议How to fix the "NoClassDefFoundError" with ADT 17和NoClassDefFoundError with Mapsforge 0.4.0 and Eclipse。没有任何帮助。
有任何想法吗?提前致谢!
MainActivity.java 的内容:
// name of the map file
private static final String MAPFILE = "austria.map";
private MapView mapView;
private TileCache tileCache;
private TileRendererLayer tileRendererLayer;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AndroidGraphicFactory.createInstance(this.getApplication());
this.mapView = new MapView(this);
setContentView(this.mapView);
this.mapView.setClickable(true);
this.mapView.getMapScaleBar().setVisible(true);
this.mapView.setBuiltInZoomControls(true);
this.mapView.getMapZoomControls().setZoomLevelMin((byte) 10);
this.mapView.getMapZoomControls().setZoomLevelMax((byte) 20);
this.tileCache = AndroidUtil.createTileCache(this, "mapcache",
mapView.getModel().displayModel.getTileSize(), 1f,
this.mapView.getModel().frameBufferModel.getOverdrawFactor());
}
@Override
protected void onStart() {
super.onStart();
this.mapView.getModel().mapViewPosition.setCenter(new LatLong(48.120539, 16.269245));
this.mapView.getModel().mapViewPosition.setZoomLevel((byte) 12);
tileRendererLayer.setMapFile(getMapFile());
tileRendererLayer.setXmlRenderTheme(InternalRenderTheme.OSMARENDER);
this.mapView.getLayerManager().getLayers().add(tileRendererLayer);
}
@Override
protected void onStop() {
super.onStop();
this.mapView.getLayerManager().getLayers().remove(this.tileRendererLayer);
this.tileRendererLayer.onDestroy();
}
@Override
protected void onDestroy() {
super.onDestroy();
this.tileCache.destroy();
this.mapView.getModel().mapViewPosition.destroy();
this.mapView.destroy();
AndroidResourceBitmap.clearResourceBitmaps();
}
private File getMapFile() {
File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), MAPFILE);
return file;
}
我的日志猫:
01-17 10:59:33.759: E/AndroidRuntime(29027): FATAL EXCEPTION: main
01-17 10:59:33.759: E/AndroidRuntime(29027): Process: com.example.mapsforgetest, PID: 29027
01-17 10:59:33.759: E/AndroidRuntime(29027): java.lang.NoClassDefFoundError: Failed resolution of: Lorg/mapsforge/map/reader/MapDatabase;
01-17 10:59:33.759: E/AndroidRuntime(29027): at org.mapsforge.map.layer.renderer.TileRendererLayer.<init>(TileRendererLayer.java:54)
01-17 10:59:33.759: E/AndroidRuntime(29027): at com.example.mapsforgetest.MainActivity.onStart(MainActivity.java:67)
01-17 10:59:33.759: E/AndroidRuntime(29027): at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1220)
01-17 10:59:33.759: E/AndroidRuntime(29027): at android.app.Activity.performStart(Activity.java:5949)
01-17 10:59:33.759: E/AndroidRuntime(29027): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2261)
01-17 10:59:33.759: E/AndroidRuntime(29027): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
01-17 10:59:33.759: E/AndroidRuntime(29027): at android.app.ActivityThread.access$800(ActivityThread.java:144)
01-17 10:59:33.759: E/AndroidRuntime(29027): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
01-17 10:59:33.759: E/AndroidRuntime(29027): at android.os.Handler.dispatchMessage(Handler.java:102)
01-17 10:59:33.759: E/AndroidRuntime(29027): at android.os.Looper.loop(Looper.java:135)
01-17 10:59:33.759: E/AndroidRuntime(29027): at android.app.ActivityThread.main(ActivityThread.java:5221)
01-17 10:59:33.759: E/AndroidRuntime(29027): at java.lang.reflect.Method.invoke(Native Method)
01-17 10:59:33.759: E/AndroidRuntime(29027): at java.lang.reflect.Method.invoke(Method.java:372)
01-17 10:59:33.759: E/AndroidRuntime(29027): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
01-17 10:59:33.759: E/AndroidRuntime(29027): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
01-17 10:59:33.759: E/AndroidRuntime(29027): Caused by: java.lang.ClassNotFoundException: Didn't find class "org.mapsforge.map.reader.MapDatabase" on path: DexPathList[[zip file "/data/app/com.example.mapsforgetest-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
01-17 10:59:33.759: E/AndroidRuntime(29027): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
01-17 10:59:33.759: E/AndroidRuntime(29027): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
01-17 10:59:33.759: E/AndroidRuntime(29027): at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
01-17 10:59:33.759: E/AndroidRuntime(29027): ... 15 more
01-17 10:59:33.759: E/AndroidRuntime(29027): Suppressed: java.lang.ClassNotFoundException: org.mapsforge.map.reader.MapDatabase
01-17 10:59:33.759: E/AndroidRuntime(29027): at java.lang.Class.classForName(Native Method)
01-17 10:59:33.759: E/AndroidRuntime(29027): at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
01-17 10:59:33.759: E/AndroidRuntime(29027): at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
01-17 10:59:33.759: E/AndroidRuntime(29027): at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
01-17 10:59:33.759: E/AndroidRuntime(29027): ... 16 more
01-17 10:59:33.759: E/AndroidRuntime(29027): Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available