不幸的是应用已停止错误 - Eclipse

时间:2014-03-16 19:06:42

标签: android eclipse android-emulator

当我在eclipse中运行我的项目时,我收到此错误:“不幸的是app已停止”,我无法运行我的项目。请帮我解决这个问题。下面是我的logcat和代码

logcat的:

03-16 15:01:49.654: D/AndroidRuntime(1238): Shutting down VM
03-16 15:01:49.654: W/dalvikvm(1238): threadid=1: thread exiting with uncaught exception (group=0xb4a2cba8)
03-16 15:01:49.744: E/AndroidRuntime(1238): FATAL EXCEPTION: main
03-16 15:01:49.744: E/AndroidRuntime(1238): Process: com.test.myfirstapp, PID: 1238
03-16 15:01:49.744: E/AndroidRuntime(1238): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.test.myfirstapp/com.test.myfirstapp.ExampleActivity}: java.lang.ClassNotFoundException: Didn't find class "com.test.myfirstapp.ExampleActivity" on path: DexPathList[[zip file "/data/app/com.test.myfirstapp-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.test.myfirstapp-1, /system/lib]]
03-16 15:01:49.744: E/AndroidRuntime(1238):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2121)
03-16 15:01:49.744: E/AndroidRuntime(1238):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
03-16 15:01:49.744: E/AndroidRuntime(1238):     at android.app.ActivityThread.access$800(ActivityThread.java:135)
03-16 15:01:49.744: E/AndroidRuntime(1238):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
03-16 15:01:49.744: E/AndroidRuntime(1238):     at android.os.Handler.dispatchMessage(Handler.java:102)
03-16 15:01:49.744: E/AndroidRuntime(1238):     at android.os.Looper.loop(Looper.java:136)
03-16 15:01:49.744: E/AndroidRuntime(1238):     at android.app.ActivityThread.main(ActivityThread.java:5017)
03-16 15:01:49.744: E/AndroidRuntime(1238):     at java.lang.reflect.Method.invokeNative(Native Method)
03-16 15:01:49.744: E/AndroidRuntime(1238):     at java.lang.reflect.Method.invoke(Method.java:515)
03-16 15:01:49.744: E/AndroidRuntime(1238):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
03-16 15:01:49.744: E/AndroidRuntime(1238):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
03-16 15:01:49.744: E/AndroidRuntime(1238):     at dalvik.system.NativeStart.main(Native Method)
03-16 15:01:49.744: E/AndroidRuntime(1238): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.test.myfirstapp.ExampleActivity" on path: DexPathList[[zip file "/data/app/com.test.myfirstapp-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.test.myfirstapp-1, /system/lib]]
03-16 15:01:49.744: E/AndroidRuntime(1238):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
03-16 15:01:49.744: E/AndroidRuntime(1238):     at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
03-16 15:01:49.744: E/AndroidRuntime(1238):     at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
03-16 15:01:49.744: E/AndroidRuntime(1238):     at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
03-16 15:01:49.744: E/AndroidRuntime(1238):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2112)
03-16 15:01:49.744: E/AndroidRuntime(1238):     ... 11 more
03-16 15:01:53.934: I/Process(1238): Sending signal. PID: 1238 SIG: 9

的manifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.test.myfirstapp"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="18" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity android:name="com.test.myfirstapp.ExampleActivity"
              android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    </application>

</manifest>

activity_main

   <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >

    <EditText
        android:id="@+id/edit_message"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1.18"
        android:hint="@string/edit_message" />

    <Button
        android:layout_width="104dp"
        android:layout_height="wrap_content"
        android:text="@string/button_send" />

</LinearLayout>

1 个答案:

答案 0 :(得分:0)

我自己是初学者,但是:

activity android:name="com.test.myfirstapp.ExampleActivity"

在代码的第15行指定android应该启动ExampleActivity。您确定这是您主要活动的名称吗?因为如果这是eclipse的默认构建,你应该有MainActivity。

在eclipse中启动一个新项目,看看默认的xml是如何存在的