This window is very depressing for a beginner of android.
For any language, the biggest possible cause of this problem is the reference of a null resource, which contains an empty image, a blank form, a null pointer, or reference.
I. Error cause
For android, I have summarized two possible errors.
1. The corresponding classes are added, but the corresponding configurations are not made in AndroidManifest. xml.
For example, I add a class derived from Activity in the source code, but do not write the following configuration in AndroidManifest. xml:
<Activity android: name = ". MainActivity"
Android: label = "@ string/app_name">
<Intent-filter>
<Action android: name = "android. intent. action. MAIN"/>
<Category android: name = "android. intent. category. LAUNCHER"/>
</Intent-filter>
</Activity>
The program may crash when running.
2. Empty reference is used.
Canvas cv = null;
Holder. unlockCanvasAndPost (cv); // display the canvas
For example, the two lines of code will report an error because the cv is empty and is not instantiated.
II. Solution to android program crash
1. Stupid Method
Set multiple breakpoints. After the Program reaches the breakpoint and crashes before the B breakpoint, you can locate the problematic interval.
2. view the log logcat
Click Debug, and then click the robot icon. The log is displayed.
The red font is incorrect. Based on it, we can locate our own errors.
Summary:
1. Whether to perform positive verification when an object is referenced
2. The stupid method and the log method can be used together. The stupid method is sometimes very effective. No matter what the method is, you can solve the problem.