about why Android force Close appears and how to fix it

Source: Internet
Author: User

There are many reasons for force close, such as null pointers, classes are not found, resources are not found, and even the order errors used by the Android API can be caused (such as Setcontentview () Findviewbyid () operation)

Force Close some people say that it is possible to use the application to completely exit and deliberately cause this problem, so that the program is forced to shut down, which I still do not use.

How to avoid ejecting the Force close window can implement the Uncaughtexception method code for the Thread.uncaughtexceptionhandler interface as follows:

Import Java.lang.Thread.UncaughtExceptionHandler;
Import android.app.Application;
public class MyApplication extends application implements Uncaughtexceptionhandler {
@Override
public void OnCreate () {
TODO auto-generated Method Stub
Super.oncreate ();
}

@Override
public void uncaughtexception (thread thread, Throwable ex) {
Thread.setdefaultuncaughtexceptionhandler (this);
}

}

To add, you want which thread can handle the uncaught exception, Thread.setdefaultuncaughtexceptionhandler (this); This code will be executed once in that thread.

about why Android force Close appears and how to fix it

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.