我正在开发一个 Android 应用程序,我在日志上得到了这个:
06-13 15:35:11.140: E/AndroidRuntime(21290): FATAL EXCEPTION: main
06-13 15:35:11.140: E/AndroidRuntime(21290): java.lang.NoClassDefFoundError: com.protocolanalyzer.andres.LogicAnalizerActivity
06-13 15:35:11.140: E/AndroidRuntime(21290): at com.multiwork.andres.MainMenu.<clinit>(MainMenu.java:37)
06-13 15:35:11.140: E/AndroidRuntime(21290): at java.lang.Class.newInstanceImpl(Native Method)
06-13 15:35:11.140: E/AndroidRuntime(21290): at java.lang.Class.newInstance(Class.java:1319)
06-13 15:35:11.140: E/AndroidRuntime(21290): at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
06-13 15:35:11.140: E/AndroidRuntime(21290): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2220)
06-13 15:35:11.140: E/AndroidRuntime(21290): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)
06-13 15:35:11.140: E/AndroidRuntime(21290): at android.app.ActivityThread.access$600(ActivityThread.java:156)
06-13 15:35:11.140: E/AndroidRuntime(21290): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1250)
06-13 15:35:11.140: E/AndroidRuntime(21290): at android.os.Handler.dispatchMessage(Handler.java:99)
06-13 15:35:11.140: E/AndroidRuntime(21290): at android.os.Looper.loop(Looper.java:137)
06-13 15:35:11.140: E/AndroidRuntime(21290): at android.app.ActivityThread.main(ActivityThread.java:5238)
06-13 15:35:11.140: E/AndroidRuntime(21290): at java.lang.reflect.Method.invokeNative(Native Method)
06-13 15:35:11.140: E/AndroidRuntime(21290): at java.lang.reflect.Method.invoke(Method.java:511)
06-13 15:35:11.140: E/AndroidRuntime(21290): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:799)
06-13 15:35:11.140: E/AndroidRuntime(21290): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:566)
06-13 15:35:11.140: E/AndroidRuntime(21290): at dalvik.system.NativeStart.main(Native Method)
当我尝试运行它时,您可以看到 Android 没有找到我的类 com.protocolanalyzer.andres.LogicAnalizerActivity,这看起来很奇怪,我所有的活动都运行得很好,但是这个特定的活动给了我这个错误。以下是我从 ListView 开始活动的方法:
private static final Class<?>[] className = {LCView.class, FrecView.class,
LogicAnalizerActivity.class, BrazoRobot.class, PruebaParser.class};
setListAdapter(new ArrayAdapter<String>(MainMenu.this, android.R.layout.simple_list_item_1, MenuNames));
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
if(DEBUG) Log.i("MainMenu", "onListItemClick() - Position: " + position);
Intent mIntent = new Intent(MainMenu.this, className[position]);
startActivity(mIntent);
}
它是我的 LogicAnalyzerActivity,你可以看到包和名称是正确的:
package com.protocolanalyzer.andres;
public class LogicAnalizerActivity extends SherlockFragmentActivity implements OnActionBarClickListener, OnNewBluetoothDataReceived{
和 Manifest.xml:
<activity
android:screenOrientation="landscape"
android:name="com.protocolanalyzer.andres.LogicAnalizerActivity"
android:label="@string/app_name" >
</activity>
怎么了?我试过了:
- 重新安装应用程序
- 擦除手机数据
- 重启 Eclipse
- 清洁工程
- 在数组中使用
com.protocolanalyzer.andres.LogicAnalizerActivity.class
而不是LogicAnalizerActivity.class