0

我试图找出导致“找不到类”异常的以下代码有什么问题,但我无法解决它。

我正在启动一个从 mapquest-android-sdk-1.0.5.jar 地图任务库扩展 MapActivity 的活动。

    public void onRoutePlanButtonClick(View v) {
        start = ((EditText) findViewById(R.id.start)).getText().toString();
        destination = ((EditText) findViewById(R.id.destination)).getText()
                .toString();

        Driver driver = new Driver();
        driver.setStart(start);
        driver.setDestination(destination);
        Intent intent = new Intent(this, DriverMap.class);
        startActivity(intent);
    }

com.thumbup.driver 中存在 DriverMap 类,但以下代码导致错误

Intent intent = new Intent(this, DriverMap.class);

笔记:

  1. 我确保地图任务库在正确的路径上
  2. 当我调用另一个 Activity 时,它可以正常工作
  3. DriverMap 扩展 ThumbUpMap 实现 ThumbUpLocationProvider
  4. 调用 DriverMap 的活动使用 SharedPreferences 在本地存储一些数据
  5. 我使用的是安卓 2.3.3

来自 LogCat(android SDK)的错误:

06-03 14:29:24.558: E/dalvikvm(1979): Could not find class 'com.thumbup.driver.DriverMap', referenced from method com.thumbup.driver.Journey.onRoutePlanButtonClick
06-03 14:29:24.558: W/dalvikvm(1979): VFY: unable to resolve const-class 58 (Lcom/thumbup/driver/DriverMap;) in Lcom/thumbup/driver/Journey;
06-03 14:29:24.558: D/dalvikvm(1979): VFY: replacing opcode 0x1c at 0x0037
06-03 14:29:24.558: D/dalvikvm(1979): VFY: dead code 0x0039-003f in Lcom/thumbup/driver/Journey;.onRoutePlanButtonClick (Landroid/view/View;)V
06-03 14:29:38.238: D/AndroidRuntime(1979): Shutting down VM
06-03 14:29:38.238: W/dalvikvm(1979): threadid=1: thread exiting with uncaught exception (group=0x40015578)
06-03 14:29:38.246: E/AndroidRuntime(1979): FATAL EXCEPTION: main
06-03 14:29:38.246: E/AndroidRuntime(1979): java.lang.IllegalStateException: Could not execute method of the activity
06-03 14:29:38.246: E/AndroidRuntime(1979):     at android.view.View$1.onClick(View.java:2154)
06-03 14:29:38.246: E/AndroidRuntime(1979):     at android.view.View.performClick(View.java:2538)
06-03 14:29:38.246: E/AndroidRuntime(1979):     at android.view.View$PerformClick.run(View.java:9152)
06-03 14:29:38.246: E/AndroidRuntime(1979):     at android.os.Handler.handleCallback(Handler.java:587)
06-03 14:29:38.246: E/AndroidRuntime(1979):     at android.os.Handler.dispatchMessage(Handler.java:92)
06-03 14:29:38.246: E/AndroidRuntime(1979):     at android.os.Looper.loop(Looper.java:123)
06-03 14:29:38.246: E/AndroidRuntime(1979):     at android.app.ActivityThread.main(ActivityThread.java:3687)
06-03 14:29:38.246: E/AndroidRuntime(1979):     at java.lang.reflect.Method.invokeNative(Native Method)
06-03 14:29:38.246: E/AndroidRuntime(1979):     at java.lang.reflect.Method.invoke(Method.java:507)
06-03 14:29:38.246: E/AndroidRuntime(1979):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
06-03 14:29:38.246: E/AndroidRuntime(1979):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
06-03 14:29:38.246: E/AndroidRuntime(1979):     at dalvik.system.NativeStart.main(Native Method)
06-03 14:29:38.246: E/AndroidRuntime(1979): Caused by: java.lang.reflect.InvocationTargetException
06-03 14:29:38.246: E/AndroidRuntime(1979):     at java.lang.reflect.Method.invokeNative(Native Method)
06-03 14:29:38.246: E/AndroidRuntime(1979):     at java.lang.reflect.Method.invoke(Method.java:507)
06-03 14:29:38.246: E/AndroidRuntime(1979):     at android.view.View$1.onClick(View.java:2149)
06-03 14:29:38.246: E/AndroidRuntime(1979):     ... 11 more
06-03 14:29:38.246: E/AndroidRuntime(1979): Caused by: java.lang.NoClassDefFoundError: com.thumbup.driver.DriverMap
06-03 14:29:38.246: E/AndroidRuntime(1979):     at com.thumbup.driver.Journey.onRoutePlanButtonClick(Journey.java:32)
06-03 14:29:38.246: E/AndroidRuntime(1979):     ... 14 more

当我切换到 Android 2.3.3 时,它正在工作!但不是 4.2.2

4

1 回答 1

0

Class not found 表明您的项目找不到类,可能是因为未包含 .jar 文件。由于您可以调用其他活动,我想您没有正确添加 jar 文件。

您确定该库包含在构建路径中吗?或者,如果您不应该将其作为库包含,您是在运行 Android 目标而不是 Google 目标吗?

尝试找到上述两个问题之一的答案,该项目将起作用!

于 2013-06-03T12:59:09.710 回答