使用OpenStreetMap API,获取jar文件的错误?的NoClassDefFoundError

时间:2012-07-05 17:53:13

标签: android openstreetmap

我正在尝试创建一个应用程序来测试如何使用OpenStreetMaps API,但是当我插入jar文件时,我会收到错误NoClassDefFoundError

堆栈跟踪

07-05 13:35:43.875: E/AndroidRuntime(9235): FATAL EXCEPTION: main
07-05 13:35:43.875: E/AndroidRuntime(9235): java.lang.ExceptionInInitializerError
07-05 13:35:43.875: E/AndroidRuntime(9235):     at com.example.osm.test.MainActivity.onCreate(MainActivity.java:16)
07-05 13:35:43.875: E/AndroidRuntime(9235):     at android.app.Activity.performCreate(Activity.java:5008)
07-05 13:35:43.875: E/AndroidRuntime(9235):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
07-05 13:35:43.875: E/AndroidRuntime(9235):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
07-05 13:35:43.875: E/AndroidRuntime(9235):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
07-05 13:35:43.875: E/AndroidRuntime(9235):     at android.app.ActivityThread.access$600(ActivityThread.java:130)
07-05 13:35:43.875: E/AndroidRuntime(9235):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
07-05 13:35:43.875: E/AndroidRuntime(9235):     at android.os.Handler.dispatchMessage(Handler.java:99)
07-05 13:35:43.875: E/AndroidRuntime(9235):     at android.os.Looper.loop(Looper.java:137)
07-05 13:35:43.875: E/AndroidRuntime(9235):     at android.app.ActivityThread.main(ActivityThread.java:4745)
07-05 13:35:43.875: E/AndroidRuntime(9235):     at java.lang.reflect.Method.invokeNative(Native Method)
07-05 13:35:43.875: E/AndroidRuntime(9235):     at java.lang.reflect.Method.invoke(Method.java:511)
07-05 13:35:43.875: E/AndroidRuntime(9235):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
07-05 13:35:43.875: E/AndroidRuntime(9235):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
07-05 13:35:43.875: E/AndroidRuntime(9235):     at dalvik.system.NativeStart.main(Native Method)
07-05 13:35:43.875: E/AndroidRuntime(9235): Caused by: java.lang.NoClassDefFoundError: org.slf4j.LoggerFactory
07-05 13:35:43.875: E/AndroidRuntime(9235):     at org.osmdroid.views.MapView.<clinit>(MapView.java:64)
07-05 13:35:43.875: E/AndroidRuntime(9235):     ... 15 more

我的活动就像这个

一样简单
public class MainActivity extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    MapView mapView = new MapView(this,256); //fails
    mapView.setClickable(true);
    mapView.setBuiltInZoomControls(true);

    setContentView(mapView);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}


}

它一旦尝试创建mapview就失败了,我想有另一个jar文件吗?目前我有osmdroid-android-3.0.8.jarosmdroid-packager-3.0.8.jarosmdroid-third-party-3.0.8.jar,但我可能不需要最后2个来实际创建地图。

任何帮助都会很棒

2 个答案:

答案 0 :(得分:1)

是的,你还需要一个罐子

NoClassDefFoundError: org.slf4j.LoggerFactory 

为您提供线索

slf4j-android-1.5.8.jar是你需要的罐子

编辑:

现在似乎有一个更晚的(1.6.6)版本,可在以下位置获得: latest slf4j

答案 1 :(得分:0)

是的,您还需要一个jar来处理来自此

的错误NoClassDefFoundError: org.slf4j.LoggerFactory

http://www.slf4j.org/android/,jar的名称为slf4j-android-1.6.1-RC1.jar [sha1]