java.lang.NoClassDefFoundError: android.os.AsyncTask

This bug occurs in an environment where you have a lot of threads running at the same time, and each thread needs to run continuously for a considerable amount of time; some of them are done with AsyncTask, and AsyncTask is executed in order after other threads.

          java.lang. NoClassDefFoundError: android .os.AsyncTask . The exception stack information (appearing in uncaughtException) is not posted here for the time being. After a lot of searching, I finally found some nutritious information:

Received: by 10.101.85.19 with SMTP id n19mr4167516anl.30.1314658242480;
        Mon, 29 Aug 2011 15:50:42 -0700 (PDT)
X-BeenThere: android


[email protected]
Received: by 10.101.181.21 with SMTP id i21ls13340762anp.4.gmail; Mon, 29 Aug
 2011 15:48:59 -0700 (PDT)
Received: by 10.101.24.5 with SMTP id b5mr2043100anj.37.1314658139241;
        Mon, 29 Aug 2011 15:48:59 -0700 (PDT)
Received: by 10.151.138.5 with SMTP id q5msybn;
        Mon, 29 Aug 2011 10:44:15 -0700 (PDT)
Received: by 10.101.168.1 with SMTP id v1mr728239ano.36.1314639855438;
        Mon, 29 Aug 2011 10:44:15 -0700 (PDT)
Date: Mon, 29 Aug 2011 10:44:14 -0700 (PDT)
From: exakoustos <[email protected]>
Reply-To: android


[email protected]
To: android


[email protected]
Message-ID: <28014072.5885.1314639854428.JavaMail.geo-discussion-forums@yqgc10>
In-Reply-To: <3208001.1407.1314283401379.JavaMail.geo-discussion-forums@yqcd38>
References: <0146c2a8-4093-4416-b2c4-d0698109cb95@a12g2000yqi.googlegroups.com>
 <CANCScgjEZ1YEHL+R9srFEkoA7wft_s=LzDpcmLnyHWTa_NM2_A@mail.gmail.com> <3abc056a-a09d-4a64-a341-a1064cd988ee@z17g2000vbp.googlegroups.com>
 <CALLdnhPdcfScNw7cScT_fcKKSR-S08qjGtbyVTb-JrQjwkbd2g@mail.gmail.com>
 <3208001.1407.1314283401379.JavaMail.geo-discussion-forums@yqcd38>
Subject: Re: [android


-developers] Re: java.lang.


NoClassDefFoundError:
 android


.os.AsyncTask
MIME-Version: 1.0
Content-Type: multipart/mixed;
	boundary="----=_Part_5883_18950387.1314639854427"

------=_Part_5883_18950387.1314639854427
Content-Type: multipart/alternative;
	boundary="----=_Part_5884_488802.1314639854427"

------=_Part_5884_488802.1314639854427
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit

Was faced with the same error when trying to launch an AsyncTask and found
that the reason it would fail was that an unrelated thread would throw
an unhanded  exception early on. It seems the AsyncTask and the other thread
(used to fetch ad banners) shared resources and when the ad thread
misbehaved it made the


class


 loader misbehave as well.

Managed to figure this out while reading your post after obsessing for 4
days. Thank you!

------=_Part_5884_488802.1314639854427
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 7bit

Was faced with the same error when trying to launch an AsyncTask and found that the reason it would fail was that an unrelated thread would throw an unhanded  exception early on. It seems the AsyncTask and the other thread (used to fetch ad banners) shared resources and when the ad thread misbehaved it made the class


 loader misbehave as well.<div><br></div><div>Managed to figure this out while reading your post after obsessing for 4 days. Thank you!</div>
------=_Part_5884_488802.1314639854427--

------=_Part_5883_18950387.1314639854427--

       The above things can be roughly understood:   because other threads and AsyncTask are competing for the same resources when loading, the AsyncTask competition fails, which further causes the class loader to fail to load it.

        How can this happen, can't figure it out?!

        View the source code http://www.oschina.net/code/explore/android-2.2-froyo/android/os/AsyncTask.java

Line 184:  Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);

       See again: http://www.oschina.net/code/explore/android-2.2-froyo/android/os/Process.java

Line 126:public static final int THREAD_PRIORITY_LOWEST = 19;

Line 136:public static final int THREAD_PRIORITY_BACKGROUND = 10;

        I really feel helpless after watching it! Adjusting thread priority seems to be no way.

        Continue to wonder: how about having the class loader load it first? ! If you know the class loader, you know (Class.forName): If a class is loaded once, it will not appear again in the future. Similar:java.lang. NoClassDefFoundError

         At this point, the problem is solved. Execute an empty AsyncTask instance directly in the front position in Application#onCreate to solve the problem.

If you can ensure your own thread order, it's okay to put AsyncTask before other threads in the current Activity. But there is no insurance in the above method.

         Finally relieved! I also really understand the dangers of thread priority.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325356851&siteId=291194637