我不知道如何找出未捕获的异常的来源。我查看了stackoverflow帖子,并尝试寻找几个解决方案。据我所知,我的活动,“监视器”,列在我的清单中,它是包的一部分。但是当我启动“Monitor”活动时,我得到一个空指针异常。我应该寻找什么才能找到这个例外?
02-03 21:44:14.192: E/Trace(19701): error opening trace file: No such file or directory (2)
02-03 21:44:14.262: I/BugSenseHandler(19701): Registering default exceptions handler
02-03 21:44:14.633: I/Setup(19701): Setup activity created
02-03 21:44:14.813: I/BugSenseHandler(19701): Flushing...
02-03 21:44:14.823: I/BugSenseHandler(19701): Registering default exceptions handler
02-03 21:44:15.023: W/BugSenseHandler(19701): Transmitting ping Exception No peer certificate
02-03 21:44:15.403: I/Adreno200-EGLSUB(19701): <ConfigWindowMatch:2087>: Format RGBA_8888.
02-03 21:44:15.594: E/(19701): <s3dReadConfigFile:75>: Can't open file for reading
02-03 21:44:15.594: E/(19701): <s3dReadConfigFile:75>: Can't open file for reading
02-03 21:44:19.318: W/dalvikvm(19701): threadid=1: thread exiting with uncaught exception (group=0x41bfb438)
02-03 21:44:22.401: E/AndroidRuntime(19701): FATAL EXCEPTION: main
02-03 21:44:22.401: E/AndroidRuntime(19701): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.mpeterson.sousvide/com.mpeterson.sousvide.Monitor}: java.lang.NullPointerException
02-03 21:44:22.401: E/AndroidRuntime(19701): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2024)
02-03 21:44:22.401: E/AndroidRuntime(19701): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2132)
02-03 21:44:22.401: E/AndroidRuntime(19701): at android.app.ActivityThread.access$600(ActivityThread.java:139)
02-03 21:44:22.401: E/AndroidRuntime(19701): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1231)
02-03 21:44:22.401: E/AndroidRuntime(19701): at android.os.Handler.dispatchMessage(Handler.java:99)
02-03 21:44:22.401: E/AndroidRuntime(19701): at android.os.Looper.loop(Looper.java:137)
02-03 21:44:22.401: E/AndroidRuntime(19701): at android.app.ActivityThread.main(ActivityThread.java:5021)
02-03 21:44:22.401: E/AndroidRuntime(19701): at java.lang.reflect.Method.invokeNative(Native Method)
02-03 21:44:22.401: E/AndroidRuntime(19701): at java.lang.reflect.Method.invoke(Method.java:511)
02-03 21:44:22.401: E/AndroidRuntime(19701): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
02-03 21:44:22.401: E/AndroidRuntime(19701): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
02-03 21:44:22.401: E/AndroidRuntime(19701): at dalvik.system.NativeStart.main(Native Method)
02-03 21:44:22.401: E/AndroidRuntime(19701): Caused by: java.lang.NullPointerException
02-03 21:44:22.401: E/AndroidRuntime(19701): at android.app.Activity.findViewById(Activity.java:1851)
02-03 21:44:22.401: E/AndroidRuntime(19701): at com.mpeterson.sousvide.Monitor.<init>(Monitor.java:51)
02-03 21:44:22.401: E/AndroidRuntime(19701): at java.lang.Class.newInstanceImpl(Native Method)
02-03 21:44:22.401: E/AndroidRuntime(19701): at java.lang.Class.newInstance(Class.java:1319)
02-03 21:44:22.401: E/AndroidRuntime(19701): at android.app.Instrumentation.newActivity(Instrumentation.java:1053)
02-03 21:44:22.401: E/AndroidRuntime(19701): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2015)
02-03 21:44:22.401: E/AndroidRuntime(19701): ... 11 more
答案 0 :(得分:6)
如果您在your_layout_file.xml中将editTextCurTemp定义为TextView,则必须调用
setContentView(R.layout.your_layout_file)
BEFORE 你做任何findViewById(),否则你会得到NPE。