简体   繁体   中英

The 'Unfortunately Testapp has stopped' error message in Android Virtual Device

I'm new at Android app developing and I try to code my first simple app to try out sending data between activities. Code compiled and I tried it to launch at Virtual Device but like title says, it stopped.

Here's logcat output:

     08-16 22:44:22.729: D/AndroidRuntime(800): Shutting down VM
     08-16 22:44:22.749: W/dalvikvm(800): threadid=1: thread exiting with uncaught exception          (group=0x414c4700)
     08-16 22:44:22.829: E/AndroidRuntime(800): FATAL EXCEPTION: main
     08-16 22:44:22.829: E/AndroidRuntime(800): java.lang.RuntimeException: Unable to    instantiate activity ComponentInfo{com.example.Testapp/com.example.Testapp.FirstActivity}:   java.lang.NullPointerException
     08-16 22:44:22.829: E/AndroidRuntime(800):     at    android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2137)
     08-16 22:44:22.829: E/AndroidRuntime(800):     at  android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
     08-16 22:44:22.829: E/AndroidRuntime(800):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
     08-16 22:44:22.829: E/AndroidRuntime(800):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
     08-16 22:44:22.829: E/AndroidRuntime(800):     at android.os.Handler.dispatchMessage(Handler.java:99)
     08-16 22:44:22.829: E/AndroidRuntime(800):     at android.os.Looper.loop(Looper.java:137)
     08-16 22:44:22.829: E/AndroidRuntime(800):     at andr     oid.app.ActivityThread.main(ActivityThread.java:5103)
     08-16 22:44:22.829: E/AndroidRuntime(800):     at java.lang.reflect.Method.invokeNative(Native Method)
     08-16 22:44:22.829: E/AndroidRuntime(800):     at  java.lang.reflect.Method.invoke(Method.java:525)
     08-16 22:44:22.829: E/AndroidRuntime(800):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
     08-16 22:44:22.829: E/AndroidRuntime(800):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
      08-16 22:44:22.829: E/AndroidRuntime(800):    at dalvik.system.NativeStart.main(Native Method)
      08-16 22:44:22.829: E/AndroidRuntime(800): Caused by: java.lang.NullPointerException
      08-16 22:44:22.829: E/AndroidRuntime(800):    at     android.app.Activity.findViewById(Activity.java:1853)
     08-16 22:44:22.829: E/AndroidRuntime(800):     at com.example.Testapp.FirstActivity.<init>(FirstActivity.java:12)
     08-16 22:44:22.829: E/AndroidRuntime(800):     at java.lang.Class.newInstanceImpl(Native Method)
     08-16 22:44:22.829: E/AndroidRuntime(800):     at java.lang.Class.newInstance(Class.java:1130)
     08-16 22:44:22.829: E/AndroidRuntime(800):     at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
08-16 22:44:22.829: E/AndroidRuntime(800):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2128)
08-16 22:44:22.829: E/AndroidRuntime(800):  ... 11 more
08-16 22:45:14.220: I/Process(800): Sending signal. PID: 800 SIG: 9
08-16 22:45:29.609: D/AndroidRuntime(903): Shutting down VM
08-16 22:45:29.619: W/dalvikvm(903): threadid=1: thread exiting with uncaught exception (group=0x414c4700)
08-16 22:45:29.679: E/AndroidRuntime(903): FATAL EXCEPTION: main
08-16 22:45:29.679: E/AndroidRuntime(903): java.lang.RuntimeException: Unable to instantiate     activity ComponentInfo{com.example.Testapp/com.example.Testapp.FirstActivity}: java.lang.NullPointerException
08-16 22:45:29.679: E/AndroidRuntime(903):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2137)
08-16 22:45:29.679: E/AndroidRuntime(903):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
08-16 22:45:29.679: E/AndroidRuntime(903):  at android.app.ActivityThread.access$600(ActivityThread.java:141)
08-16 22:45:29.679: E/AndroidRuntime(903):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
08-16 22:45:29.679: E/AndroidRuntime(903):  at android.os.Handler.dispatchMessage(Handler.java:99)
08-16 22:45:29.679: E/AndroidRuntime(903):  at android.os.Looper.loop(Looper.java:137)
08-16 22:45:29.679: E/AndroidRuntime(903):  at android.app.ActivityThread.main(ActivityThread.java:5103)
08-16 22:45:29.679: E/AndroidRuntime(903):  at java.lang.reflect.Method.invokeNative(Native Method)
08-16 22:45:29.679: E/AndroidRuntime(903):  at     java.lang.reflect.Method.invoke(Method.java:525)
08-16 22:45:29.679: E/AndroidRuntime(903):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
08-16 22:45:29.679: E/AndroidRuntime(903):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-16 22:45:29.679: E/AndroidRuntime(903):  at dalvik.system.NativeStart.main(Native Method)
08-16 22:45:29.679: E/AndroidRuntime(903): Caused by: java.lang.NullPointerException
08-16 22:45:29.679: E/AndroidRuntime(903):  at android.app.Activity.findViewById(Activity.java:1853)
08-16 22:45:29.679: E/AndroidRuntime(903):  at com.example.Testapp.FirstActivity.<init>(FirstActivity.java:12)
08-16 22:45:29.679: E/AndroidRuntime(903):  at java.lang.Class.newInstanceImpl(Native Method)
08-16 22:45:29.679: E/AndroidRuntime(903):  at java.lang.Class.newInstance(Class.java:1130)
08-16 22:45:29.679: E/AndroidRuntime(903):  at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
08-16 22:45:29.679: E/AndroidRuntime(903):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2128)
08-16 22:45:29.679: E/AndroidRuntime(903):  ... 11 more

Can anybody tell, what error this log references and where I should look for to fix this issue.

All the best

Can anybody tell, what error this log references and where I should look for to fix this issue.

This first line with the exception after

FATAL EXCEPTION: main
 08-16 22:44:22.829: E/AndroidRuntime(800): java.lang.RuntimeException: Unable to    instantiate activity ComponentInfo{com.example.Testapp/com.example.Testapp.FirstActivity}:   java.lang.NullPointerException

Caused by: java.lang.NullPointerException

tells us that there is a NPE . Then if we find the first line that references your project it will tell us the line number

at com.example.Testapp.FirstActivity.<init>(FirstActivity.java:12)

Something is null at line 12 of FirstActivity . Most likely instantiating a View before inflating the layout but could be about anything.

If you are having trouble figuring out what/why something is null then please post the lines around line 12.

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