03-27 23:36:32.936 32641 32641 D testapp : onCreate 03-27 23:36:55.858 32641 32641 E AndroidRuntime: FATAL EXCEPTION: main 03-27 23:36:55.858 32641 32641 E AndroidRuntime: Process: com.example.crashinfo, PID: 32641 03-27 23:36:55.858 32641 32641 E AndroidRuntime: java.lang.IllegalStateException: Could not execute method for android:onClick 03-27 23:36:55.858 32641 32641 E AndroidRuntime: at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:414) 03-27 23:36:55.858 32641 32641 E AndroidRuntime: at android.view.View.performClick(View.java:7448) 03-27 23:36:55.858 32641 32641 E AndroidRuntime: at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:992) 03-27 23:36:55.858 32641 32641 E AndroidRuntime: at android.view.View.performClickInternal(View.java:7425) 03-27 23:36:55.858 32641 32641 E AndroidRuntime: at android.view.View.access$3600(View.java:810) 03-27 23:36:55.858 32641 32641 E AndroidRuntime: at android.view.View$PerformClick.run(View.java:28305) 03-27 23:36:55.858 32641 32641 E AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:938) 03-27 23:36:55.858 32641 32641 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:99) 03-27 23:36:55.858 32641 32641 E AndroidRuntime: at android.os.Looper.loop(Looper.java:223) 03-27 23:36:55.858 32641 32641 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:7656) 03-27 23:36:55.858 32641 32641 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method) 03-27 23:36:55.858 32641 32641 E AndroidRuntime: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) 03-27 23:36:55.858 32641 32641 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) 03-27 23:36:55.858 32641 32641 E AndroidRuntime: Caused by: java.lang.reflect.InvocationTargetException 03-27 23:36:55.858 32641 32641 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method) 03-27 23:36:55.858 32641 32641 E AndroidRuntime: at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:409) 03-27 23:36:55.858 32641 32641 E AndroidRuntime: ... 12 more 03-27 23:36:55.858 32641 32641 E AndroidRuntime: Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference 03-27 23:36:55.858 32641 32641 E AndroidRuntime: at com.example.crashinfo.MainActivity.click(MainActivity.java:23) 03-27 23:36:55.858 32641 32641 E AndroidRuntime: ... 14 more
// ANDROID_ROOT/frameworks/base/core/java/com/android/internal/os/RuntimeInit.java /** * Logs a message when a thread encounters an uncaught exception. By * default, {@link KillApplicationHandler} will terminate this process later, * but apps can override that behavior. */ privatestaticclassLoggingHandlerimplementsThread.UncaughtExceptionHandler { publicvolatilebooleanmTriggered=false;
// Don't re-enter if KillApplicationHandler has already run if (mCrashing) return;
// mApplicationObject is null for non-zygote java programs (e.g. "am") // There are also apps running with the system UID. We don't want the // first clause in either of these two cases, only for system_server. if (mApplicationObject == null && (Process.SYSTEM_UID == Process.myUid())) { Clog_e(TAG, "*** FATAL EXCEPTION IN SYSTEM PROCESS: " + t.getName(), e); } else { StringBuildermessage=newStringBuilder(); // The "FATAL EXCEPTION" string is still used on Android even though // apps can set a custom UncaughtExceptionHandler that renders uncaught // exceptions non-fatal. message.append("FATAL EXCEPTION: ").append(t.getName()).append("\n"); finalStringprocessName= ActivityThread.currentProcessName(); if (processName != null) { message.append("Process: ").append(processName).append(", "); } message.append("PID: ").append(Process.myPid()); Clog_e(TAG, message.toString(), e); } } }
并且我们在同一个文件下面不远处可以看到这样一段代码
1 2 3 4 5 6 7 8 9 10 11 12
@Override publicvoiduncaughtException(Thread t, Throwable e) { try { ...... } catch (Throwable t2) { ...... } finally { // Try everything to make sure this process goes away. Process.killProcess(Process.myPid()); System.exit(10); } }
//frameworks/base/core/java/android/os/Process.java /** * Kill the process with the given PID. * Note that, though this API allows us to request to * kill any process based on its PID, the kernel will * still impose standard restrictions on which PIDs you * are actually able to kill. Typically this means only * the process running the caller's packages/application * and any additional processes created by that app; packages * sharing a common UID will also be able to kill each * other's processes. */ publicstaticfinalvoidkillProcess(int pid) { sendSignal(pid, SIGNAL_KILL); }
//frameworks/base/core/java/android/os/Process.java /** * Send a signal to the given process. * * @param pid The pid of the target process. * @param signal The signal to send. */ publicstaticfinalnativevoidsendSignal(int pid, int signal);