What you don't know about android (1) sudden death of the android Program

Source: Internet
Author: User

 

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.