简体   繁体   中英

Hello Android Stops Unexpectedly

I have searched the internet for days and have found dozens of solutions none of which work. So I thought I'd post my situation:

I have installed eclipse and the 2.3.3 android SDK onto my laptop, put the code in for hello world (or hello android) and clicked run. The emulator starts but when the activity is run I get the message "SORRY! the application Hello Android (process com.example helloandroid) has stopped unexpectedly. Please try again"

package com.example.helloandroid;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class HelloAndroid extends Activity {
   /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       TextView tv = new TextView(this);
       tv.setText("Hello, Android");
       setContentView(tv);
   }
}

and this is log cat

02-03 12:54:59.470: D/AndroidRuntime(356): Shutting down VM
02-03 12:54:59.470: W/dalvikvm(356): threadid=1: thread exiting with uncaught exception (group=0x40015560)
02-03 12:54:59.521: E/AndroidRuntime(356): FATAL EXCEPTION: main
02-03 12:54:59.521: E/AndroidRuntime(356): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.helloandroid/com.example.helloandroid.HelloAndroidActivity}: java.lang.ClassNotFoundException: com.example.helloandroid.HelloAndroidActivity in loader dalvik.system.PathClassLoader[/data/app/com.example.helloandroid-1.apk]
02-03 12:54:59.521: E/AndroidRuntime(356):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1569)
02-03 12:54:59.521: E/AndroidRuntime(356):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
02-03 12:54:59.521: E/AndroidRuntime(356):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
02-03 12:54:59.521: E/AndroidRuntime(356):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
02-03 12:54:59.521: E/AndroidRuntime(356):  at android.os.Handler.dispatchMessage(Handler.java:99)
02-03 12:54:59.521: E/AndroidRuntime(356):  at android.os.Looper.loop(Looper.java:123)
02-03 12:54:59.521: E/AndroidRuntime(356):  at android.app.ActivityThread.main(ActivityThread.java:3683)
02-03 12:54:59.521: E/AndroidRuntime(356):  at java.lang.reflect.Method.invokeNative(Native Method)
02-03 12:54:59.521: E/AndroidRuntime(356):  at java.lang.reflect.Method.invoke(Method.java:507)
02-03 12:54:59.521: E/AndroidRuntime(356):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
02-03 12:54:59.521: E/AndroidRuntime(356):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
02-03 12:54:59.521: E/AndroidRuntime(356):  at dalvik.system.NativeStart.main(Native Method)
02-03 12:54:59.521: E/AndroidRuntime(356): Caused by: java.lang.ClassNotFoundException: com.example.helloandroid.HelloAndroidActivity in loader dalvik.system.PathClassLoader[/data/app/com.example.helloandroid-1.apk]
02-03 12:54:59.521: E/AndroidRuntime(356):  at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
02-03 12:54:59.521: E/AndroidRuntime(356):  at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
02-03 12:54:59.521: E/AndroidRuntime(356):  at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
02-03 12:54:59.521: E/AndroidRuntime(356):  at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
02-03 12:54:59.521: E/AndroidRuntime(356):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)
02-03 12:54:59.521: E/AndroidRuntime(356):  ... 11 more
02-03 12:59:59.691: I/Process(356): Sending signal. PID: 356 SIG: 9
02-03 13:00:33.371: D/AndroidRuntime(366): Shutting down VM
02-03 13:00:33.371: W/dalvikvm(366): threadid=1: thread exiting with uncaught exception (group=0x40015560)
02-03 13:00:33.431: E/AndroidRuntime(366): FATAL EXCEPTION: main
02-03 13:00:33.431: E/AndroidRuntime(366): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.helloandroid/com.example.helloandroid.HelloAndroidActivity}: java.lang.ClassNotFoundException: com.example.helloandroid.HelloAndroidActivity in loader dalvik.system.PathClassLoader[/data/app/com.example.helloandroid-1.apk]
02-03 13:00:33.431: E/AndroidRuntime(366):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1569)
02-03 13:00:33.431: E/AndroidRuntime(366):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
02-03 13:00:33.431: E/AndroidRuntime(366):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
02-03 13:00:33.431: E/AndroidRuntime(366):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
02-03 13:00:33.431: E/AndroidRuntime(366):  at android.os.Handler.dispatchMessage(Handler.java:99)
02-03 13:00:33.431: E/AndroidRuntime(366):  at android.os.Looper.loop(Looper.java:123)
02-03 13:00:33.431: E/AndroidRuntime(366):  at android.app.ActivityThread.main(ActivityThread.java:3683)
02-03 13:00:33.431: E/AndroidRuntime(366):  at java.lang.reflect.Method.invokeNative(Native Method)
02-03 13:00:33.431: E/AndroidRuntime(366):  at java.lang.reflect.Method.invoke(Method.java:507)
02-03 13:00:33.431: E/AndroidRuntime(366):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
02-03 13:00:33.431: E/AndroidRuntime(366):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
02-03 13:00:33.431: E/AndroidRuntime(366):  at dalvik.system.NativeStart.main(Native Method)
02-03 13:00:33.431: E/AndroidRuntime(366): Caused by: java.lang.ClassNotFoundException: com.example.helloandroid.HelloAndroidActivity in loader dalvik.system.PathClassLoader[/data/app/com.example.helloandroid-1.apk]
02-03 13:00:33.431: E/AndroidRuntime(366):  at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
02-03 13:00:33.431: E/AndroidRuntime(366):  at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
02-03 13:00:33.431: E/AndroidRuntime(366):  at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
02-03 13:00:33.431: E/AndroidRuntime(366):  at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
02-03 13:00:33.431: E/AndroidRuntime(366):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)
02-03 13:00:33.431: E/AndroidRuntime(366):  ... 11 more
02-03 13:05:33.600: I/Process(366): Sending signal. PID: 366 SIG: 9

尝试将setContentView()方法移至textview初始化上方

It seems to be something wrong with the way your emulator is set up. Did you follow this tutorial especially the "Setting up the AVD" part?

I would start the install of the emulator all over again. Also you could send him a copy of your program and if he can successfully run your project in the emulator then you know you just need to get your emulator set up correctly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM