gpt4 book ai didi

java - Android虚拟设备中的 'Unfortunately Testapp has stopped'错误消息

转载 作者:行者123 更新时间:2023-12-01 14:13:58 24 4
gpt4 key购买 nike

我是 Android 应用程序开发新手,我尝试编写我的第一个简单应用程序来尝试在 Activity 之间发送数据。代码已编译,我尝试在虚拟设备上启动它,但正如标题所示,它停止了。

这是 logcat 输出:

     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.

第一行,后面有异常(exception)

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

告诉我们有一个NPE。然后,如果我们找到引用您的项目的第一行,它将告诉我们行号

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

FirstActivity 第 12 行,有东西是 null。最有可能在膨胀布局之前实例化View,但可以是任何东西。

如果您无法弄清楚什么/为什么某些内容为 null,请发布第 12 行周围的行。

关于java - Android虚拟设备中的 'Unfortunately Testapp has stopped'错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18281706/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com