W/dalvikvm:threadid=1:thread exiting with uncaught exception (GROUP=0X419B4C50)

Source: Internet
Author: User
Tags thread class throwable try catch



Today I encountered a problem with the programming: W/dalvikvm:threadid=1:thread exiting with uncaught exception (GROUP=0X419B4C50) ....
Log completely did not,,, this time the intention to kill thieves, powerless Ah,,,,, what error messages are not.

Baidu Solutions to various problems, and finally an article: Http://blog.csdn.net/liqiangeastsun/article/details/43986605 said a solution to the problem:
The following is the original text:

Android error Threadid=1:thread exiting with uncaught exception (GROUP=0X416298C8)

Crashes when testing in project development, error as above
This error means that there are exceptions that are not caught in the thread. In general, catch exceptions using

Try 
 {
 } 
 catch (Exception e)
 {
 }
1 2 3 4 5 6 1 2 3 4 5-6

But in the thread pool, the thread pool catches all the exceptions when it executes the task, so all the exceptions in the thread cannot catch the thrown exception.
That is, a try catch catches no exceptions.
There is an interface in Java, Uncaughtexceptionhandler described as follows:

Static interface Thread.uncaughtexceptionhandler 
//When Thread terminates abruptly because of an unhandled exception, the interface of the handler is invoked.
1 2 1 2

A method in the thread class

static void
Setdefaultuncaughtexceptionhandler (thread.uncaughtexceptionhandler eh) 
//set to terminate abruptly when a thread has not caught an exception And the default handler that is invoked when no other handler is defined for the thread.
1 2 3 1 2 3

We need to implement such an interface Uncaughtexceptionhandler, and then set up handlers in the main thread of the program.
The code is as follows

Import Java.lang.Thread.UncaughtExceptionHandler;

Implements Uncaughtexceptionhandler public
class The extends activity implements Uncaughtexceptionhandler {


//must implement Interface Uncaughtexception
@Override public
void Uncaughtexception (Thread arg0, Throwable arg1) {
        // Handling exceptions here, Arg1 is the exception caught  
        log.i ("AAA", "uncaughtexception   " + arg1);
    }


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

It is not yet possible to catch the exception in the thread, and you need to call a method

Thread.setdefaultuncaughtexceptionhandler (this);
1 1

You can call it in the OnCreate method

@Override
protected void onCreate (Bundle savedinstancestate) {
    //Call the following method in the OnCreate method, and then use the thread, The exception Thread.setdefaultuncaughtexceptionhandler (this) can be caught in the Uncaughtexception method
    ;
1 2 3 4 5 1 2 3 4 5

The complete code is as follows

    Import Package Imports Java.lang.Thread.UncaughtExceptionHandler;

    Implements Uncaughtexceptionhandler public class The extends activity implements Uncaughtexceptionhandler {
        @Override protected void OnCreate (Bundle savedinstancestate) {//TODO auto-generated method stub
        Super.oncreate (savedinstancestate);
        Setcontentview (r.layout.th);

        The following method is called here to capture the exception Thread.setdefaultuncaughtexceptionhandler in the thread (this);
        Gets the button btn1 = (button) Findviewbyid (R.ID.BTN) that was created; Add a hit listener event Btn1.setonclicklistener to BTN1 (new Onclicklistener () {@Override public void on
            Click (View arg0) {//Call my own method Init ();
    }
        });   
            public void Init () {//Open thread new Handler (Looper.getmainlooper ()). Post (new Runnable () {
              @Override public void Run () {//Here a try catch is unable to catch an exception  try {////////////////////////////////////////////requires a method called in the thread Purchase.init (cont
                    Ext, Iaplistener) purchase.init (context, iaplistener); catch (Exception e) {//Todo:handle exc
                    Eption log.i ("AAA", "Inig" + e);
                E.printstacktrace ();
    }
            }
        }); //must implement Interface uncaughtexception @Override public void uncaughtexception (Thread arg0, throwable arg1) {//
    Handling exceptions here, Arg1 is the catch of the exception log.i ("AAA", "uncaughtexception" + arg1); }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26-27--28 29---30 31--32 33 34 35 36 37 38-39 40 41 42 45 46 47 48 49 50 51 52 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18-19--20 21---22 23--24 25 26 27 28 29 30-31 32 33 34 6 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51-52

This will catch the exception in the thread again, without causing the project to crash directly


Finally can print out log information, the error is: (Android5.0 above the problem, 5, 0 below the problem) java.lang.classcastexception:android.view.viewgroup$ Layoutparams cannot be cast to Android.widget.abslistview$layoutparams
The problem is obvious, the problem of the class-Time report:
Solution:

Android.view.ViewGroup.LayoutParams
To
Android.widget.AbsListView.LayoutParams



The problem is not very critical, the main problem is to find the method, when the log can not display the exception information,,,,,,,,,,,, can help us print out log information, and then analyze the problem, solve the problem ....


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.