Classnotfoundexception Android
Solution 1:
privatestaticvoidfixClassLoaderIssue()
{
ClassLoader myClassLoader = MyClass.class.getClassLoader();
Thread.currentThread().setContextClassLoader(myClassLoader);
}
This is the code I currently have that I believe fixed this problem. MyClass is just a class I have in my project. Like I said, a co-worked showed it to me, but it seems pretty straight forward.
Solution 2:
Are there any other reasons a ClassNotFoundException is thrown?
IIRC, it can also be thrown if some other class in the static dependencies of "com.package.mycode.Class" cannot be loaded, or if there is a problem during static initialization. But these should show up as a nested exception ... the first time you attempt to load the class.
Solution 3:
Android has not all Java classes available that are available on a normal machine. There are some classes missing that could cause this error. But this should be already be shown at compile time. Look at this list to see which classes are supported and which are not supported.
Again I'm only guessing because the compiler should see the missing classes.
Solution 4:
For an android app, I'd same issue with an external jar file. In my case the solution was to move the jar from "lib" folder to the android default "libs" folder.
When the jar was in lib folder (was added to build path as well), while there are was no build issue in Eclipse, the app was giving ClassNotFoundException at runtime. Once I moved the jar to "libs" folder, the jar started appearing under "Android Dependencies" and app started working fine.
These are some of the other discussions about the same topic.
Adding a library/JAR to an Eclipse Android project
Android: What is the folder name of the jar files (LIB or LIBS)?
How to specify lib folder for JARs when using Android-generated ant build file?
Solution 5:
i had a problem starting an aynctask. it used to work just fine but then i added
line = StringEscapeUtils.unescapeHtml4(line);
(its a commons.apache.org library) to the asynctask then lots of problems. it compiles ok but when i tried to run, it said class not found on my asynctask class. but it i hit resume it kept going in the async task, then it died.
so i guess the problem is StringEscapeUtils isn't installed properly, but i had no way of figuring that out from the error messages i was getting.
Post a Comment for "Classnotfoundexception Android"