我正在尝试根据斯坦福移动计算机视觉课程http://web.stanford.edu/class/cs231m/实施“HelloAndroid”。我遇到了“ClassNotFoundException”问题。在Android模拟器上它说“不幸的是,HelloAndroid已经停止了”。 Eclipse中的LogCat显示以下内容:
04-17 22:28:47.180: D/AndroidRuntime(2036): Shutting down VM
04-17 22:28:47.180: D/AndroidRuntime(2036): --------- beginning of crash
04-17 22:28:47.180: E/AndroidRuntime(2036): FATAL EXCEPTION: main
04-17 22:28:47.180: E/AndroidRuntime(2036): Process: edu.stanford.cs231m, PID: 2036
04-17 22:28:47.180: E/AndroidRuntime(2036): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{edu.stanford.cs231m/edu.stanford.cs231m.HelloAndroidActivity}: java.lang.ClassNotFoundException: Didn't find class "edu.stanford.cs231m.HelloAndroidActivity" on path: DexPathList[[zip file "/data/app/edu.stanford.cs231m-1/base.apk"],nativeLibraryDirectories=[/vendor/lib64, /system/lib64]]
04-17 22:28:47.180: E/AndroidRuntime(2036): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2209)
04-17 22:28:47.180: E/AndroidRuntime(2036): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
04-17 22:28:47.180: E/AndroidRuntime(2036): at android.app.ActivityThread.access$800(ActivityThread.java:144)
04-17 22:28:47.180: E/AndroidRuntime(2036): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
04-17 22:28:47.180: E/AndroidRuntime(2036): at android.os.Handler.dispatchMessage(Handler.java:102)
04-17 22:28:47.180: E/AndroidRuntime(2036): at android.os.Looper.loop(Looper.java:135)
04-17 22:28:47.180: E/AndroidRuntime(2036): at android.app.ActivityThread.main(ActivityThread.java:5221)
04-17 22:28:47.180: E/AndroidRuntime(2036): at java.lang.reflect.Method.invoke(Native Method)
04-17 22:28:47.180: E/AndroidRuntime(2036): at java.lang.reflect.Method.invoke(Method.java:372)
04-17 22:28:47.180: E/AndroidRuntime(2036): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
04-17 22:28:47.180: E/AndroidRuntime(2036): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
04-17 22:28:47.180: E/AndroidRuntime(2036): Caused by: java.lang.ClassNotFoundException: Didn't find class "edu.stanford.cs231m.HelloAndroidActivity" on path: DexPathList[[zip file "/data/app/edu.stanford.cs231m-1/base.apk"],nativeLibraryDirectories=[/vendor/lib64, /system/lib64]]
04-17 22:28:47.180: E/AndroidRuntime(2036): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
04-17 22:28:47.180: E/AndroidRuntime(2036): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
04-17 22:28:47.180: E/AndroidRuntime(2036): at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
04-17 22:28:47.180: E/AndroidRuntime(2036): at android.app.Instrumentation.newActivity(Instrumentation.java:1065)
04-17 22:28:47.180: E/AndroidRuntime(2036): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2199)
04-17 22:28:47.180: E/AndroidRuntime(2036): ... 10 more
04-17 22:28:47.180: E/AndroidRuntime(2036): Suppressed: java.lang.ClassNotFoundException: edu.stanford.cs231m.HelloAndroidActivity
04-17 22:28:47.180: E/AndroidRuntime(2036): at java.lang.Class.classForName(Native Method)
04-17 22:28:47.180: E/AndroidRuntime(2036): at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
04-17 22:28:47.180: E/AndroidRuntime(2036): at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
04-17 22:28:47.180: E/AndroidRuntime(2036): at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
04-17 22:28:47.180: E/AndroidRuntime(2036): ... 13 more
04-17 22:28:47.180: E/AndroidRuntime(2036): Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
供参考,java代码是
package edu.stanford.cs231m.helloandroid;
import android.widget.TextView;
import android.app.Activity;
import android.os.Bundle;
public class HelloAndroidActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
TextView txtView = new TextView(this);
txtView.setText("Hello czAndroid!");
setContentView(txtView);
super.onCreate(savedInstanceState);
}
}
manifest.xml是
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="edu.stanford.cs231m"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="21"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="HelloAndroidActivity"
android:label="@string/app_name"
android:screenOrientation="landscape">
<intent-filter>
<category android:name="android.intent.category.LAUNCHER"/>
<action android:name="android.intent.action.MAIN"/>
</intent-filter>
</activity>
</application>
</manifest>
如果重要,模拟器的详细信息如下:
我已经为此工作了将近一天,并尝试了一些方法,例如在“HelloAndroidActivity”中添加一个点,选择java构建路径中的所有项目等,但这些都不起作用。
答案 0 :(得分:0)
事实证明,我的manifest.xml包名写错了。我写了
package="edu.stanford.cs231m"
正确的应该是
package="edu.stanford.cs231m.helloandroid"
问题解决了。