Regarding NoClassDefFoundError - android

I have used the isEmpty and isBlank methods of apache's StringUtils Class. These methods worked in a fine manner, after couple of weeks suddenly i got the error
java.lang.NoClassDefFoundError: org.apache.commons.lang3.StringUtils
I was confused why this error happened suddenly.It would be fine if anyone help me to understand this suddenly happened.
People Saying that apache might have changed the definitionin their JAR file, is it a right one,i really confused why this suddenly happened , i removed the old jar from my build path and downloaded the same version of New Jar and added it to Build path, then this issue is resloved.
It is happening in the Market Code , there's no interaction with ADT and market code
so really confused on this issue?

This occurred to me too - after updating the Android SDK Tools. In current version (19), what you need to do is:
make libs/ folder in project's root directory, and put all jars there (folder's name is fixed "libs")
after this, go to project properties --> Java Build Path --> Libraries, and remove all custom jars you previously added

NoClassDefFoundError says NoClassDefFoundError is Thrown if the JVM or a ClassLoader instance tries to load in the definition of a class and no definition of the class could be found.
Maybe startup script is overriding Classpath environment variable.

Related

java.lang.NoClassDefFoundError with external jars in Android project

I've been searching the internet for two days now, and I feel like I've tried everything.
Please let me know if any code snippets might be helpful in finding a solution.
I've created an android application with the standard login activity. In the doInBackground()-method, I invoke a static method from another external class. Since this method will be invoked once the submit button is clicked, the error occurs during runtime. The class is included in my file, and there are no compilation errors. Whenever I tap/click on the Submit-button, I get a java.lang.NoClassDefFoundError referring to a class (in my external jar) that is used and properly included in my external file I refer to in the doInBackground()-method.
All my external libraries are in the 'libs'-folder. I've tried adding them to the build path manually instead and checking the boxes next to them in the 'order and export'-tab instead of the checkbox next to the 'Android Private Libraries' entry. I've tried putting the 'gen'-directory above the 'src'-directory, which didn't change anything either. Restarting eclipse, reimporting the project as a whole, playing around with the order of the external libraries in the build path, fixing project properties and cleaning the project over and over, nothing helped. I've checked this
http://javarevisited.blogspot.de/2011/06/noclassdeffounderror-exception-in.html
and tried every solution, but none of them worked for me. I ad a similar problem with a library before, and I could solve it by changing some build path settings and restarting Eclipse. However, this just doesn't work for me any more. I hope anybody has another solution or an idea, I have no clue what's wrong...
Thank you all in advance!
Yeehaw
Edit:
Despite creating a whole new project and adding my previous files to this new project, I still had the same problem in the new project. I think I figured out where this error came from: When I added my external library, I still had dependencies from the just added .jar to other jars. After adding those as well, the compiler said I needed the java.rmi.Remote class, which is in Java's JRE system library (rt.jar). Adding the whole jre library to my project made the compiler error disappear, the runtime error, however, still persisted.
After some more research I found out that my external library is probably not compatible with the android runtime environment, which means that the jar's .class-files don't have an equivalent .dex-representation which is neededfor the Dalvik virtualmachine on android powered devices. For many java jar's, especially those designed for use with the android platform, those problems don't occur.
Please correct me if I'm wrong, but this explanation seemed pretty plausible to me. Too bad, since this is the only way to currently access our database programmatically.
Make sure you've updated to the latest version of ADT Eclipse plugin and SDK Tools and also make sure "Android Dependencies" is checked in your project properties.

Jar file versus reference to the Android Library

You will really make my day by explaining the following nuissance.
L is a library. A is an application using L, CA is a class, declared in A extending a class CL in the library L.
Untill recently, I could just place L.jar in the lib folder of A project. But I purchased a new hard disk, reset Eclipse, ADT plugin and SDK, then transferred my project to the new location. This is when it started.
If I place in A a reference to the project L (via Project/Properties/Android/Library), everything still works all right. But with a jar file, it gives a "No Class Defintion Found" error for CA class, even though it belongs to the same class as the calling method!
To avoid some sceptical remarks:
L has no resources in it.
Compiler version is 1.6
I cleaned both projects millions of times.
Both projects are compiled with same API version.
No obfuscation was used and I checked that CL class is really present in L.jar.
Tried placing L.jar in build path, as topmost, then as bottommost - no help.
Thank you for anticipated help.
It was rather silly of me: in "Order and Export" panel of BuildPath configuration I had Android Dependencies ticked, but Android Provite Libraries unticked.
What I found out is that libraries linked through Android properties go to Android Dependencies, whereas the ones in lib folder are considered as Android Private. This explains why the first were included, while second weren't.
The most annoying thing is that Eclipse doesn't complain, the build seems to be all right, and only at the execution stage the error comes out. As a C programmer I am not quite used to that :)

Android - NoClassDefFoundError after jar changed

I know that there are some similar questions, but no solution helped me.
I am getting a java.lang.NoClassDefFoundError when I try to access an (existing) class
in a self-created .jar from my projectgroup.
This .jar works fine in an normal javaProject but doesn´t work with Android.
But an older version of this .jar worked fine with Android.
I am developing with Eclipse + Android Development Tool - Plugin (Version 21)
I have put the .jar in the Project_Home/libs folder.
There are no errors at compiletime.
Before the exception was thrown, there was some "dalvikvm - could not find class ... referenced from ..." errors.
I think, there could be a problem with the Java Version, because our projectgroup recently started to use Java 7, but I am not sure and have no idea how to fix it.
Thanks a lot for your help.
Rename your lib to libs and update the build path and then try again
I think if the project is compiling fine then we can rule out any error in copying or java buildpath. The only other time i get this error is when my import is wrong in the code. I would suggest you to re-check your import and recreate R.java file.
Make sure that your classes do not have same names as ones already present within Android. Upon building the package, due to "optimization" classes with same names are omitted.
Android libraries are mostly compiled against 1.5. Not all libraries are also present within Android. Your package may depend on some other library that is not present within the system.
Ordinarily I don't want to answer my own question but I hope it will help someone.
I didn't see an other warning (not in Logcat, it was in the console):
"Dx bad class file magic (cafebabe) or version (0033.0000)"
I had found this Warning in an other Stackoverflow question.
I had opened one of the class file from the not working .jar with an HexEditor
and changed the Major-Version-Byte to 0x32 and it worked.
I know this is not a solution, because there could be features from Java 7 in the class,
so the class file no longer work, but it proves that it was a problem with the Java version

Android: NoClassDefFound error

My setup is as follows:
I have an android project A, and a java project B. Project A uses some files from Project B.
My development environment is eclipse, and I have included Project B in the build path,
as well as marked it for 'Order and export'.
The project builds fine, but at runtime I get a
java.lang.NoClassDefFound error, when I am trying to reference a class from Project B.
How can I resolve this?
I am using eclipse Juno, and ADT 20.0.3.
Thanks.
As you talk about having updated your Eclipse and your ADT, maybe you also changed your environment to Java 7?
If that is the case, the answer would be:
Switch back to Java 1.6.x, as Java 7 is not (yet?) supported by Android.
You need to change the "compiler compliance level" under:
Window - Preferences -- Java - Compiler - Compiler compliance level
Hope that works, at least it did for me:
NoClassDefFoundError when referencing from an Android-Project to a standard Java-Project
You can also try to export the java classes you need in a jar, and include that jar in your Android project.
I had the same problem when I was trying to reference another class withing the same project itself.In my case, the problem was solved when I rechecked the android dependencies. I added two jar files for a single required file. There was a need of android-support-v4.jar file in my project. I added the library twice by mistake. The error was resolved when I deleted one of them.
For me this was happening when using the AIDE development environment. It has happened a couple of times over the past year.
When the Java diamond operator is used to specify a function's generic type the program will compile, but the Dalvic engine crashes with the NoClassDefFound exception.
To fix this I had to explicitly define the generic type.
By the way, this crash can happen in a completely different place to where the problem actually is. For example, we have classes A and B. The bad code is at A.myMethod(). The crash will happen when class B attempts to access any part of class A, even something unrelated such as A.myOther() method.
This is because of how Java/Dalvic loads classes at runtime only when first accessed.

Conversion to Dalvik format failed with error 1 with javax/net/SocketFactory.class

Encounter this problem when trying to Build Project getting such output in console:
[2010-07-19 23:29:23 - myProject]
trouble processing "javax/net/SocketFactory.class":
[2010-07-19 23:29:23 - myProject]
Attempt to include a core VM class in something other than a core library.
It is likely that you have attempted to include the core library from a desktop
virtual machine into an application, which will most assuredly not work. If
you really intend to build a core library -- which is only appropriate as
part of creating a full virtual machine binary, as opposed to compiling an
application -- then use the "--core-library" option to suppress this error
message. If you go ahead and use "--core-library" but are in fact building
an application, then please be aware that your build will still fail at some
point; you will simply be denied the pleasure of reading this helpful error
message.
[2010-07-19 23:29:23 - myProject] 1 error; aborting
[2010-07-19 23:29:23 - myProject] Conversion to Dalvik format failed with error 1
I was looking for my project to use the package javax, not found, clean all also does not help. what I am doing wrong?
Update
Sorry guys, but I could not find good fix for that, I want to emphasize the fact, that i dont use SocketFactory class in my project at all! source code was not changed before this problem, and that's why i think that problem in eclipse or adt or something else, BUT if i use ant(generated by sdk) to build this project there is no problem!!!
I solve this problem by removing Eclipse, Android SDK, Eclipse workspace, and just reinstall them, after this all works fine for now.
Hope this will help someone.
I had the same problem..
This worked for me
project-->properties->java build path->libraries-> remove all including android jars
now go the project browser, right click on the project you are working on,
then android tools---> fix project properties...
do a clean and then build...
I solved the problem (at least for me).
Here's what I did:
Go to Project » Properties » Java Build Path » Libraries
Remove all except the "Android X.Y" click OK.
Go to Project » Clean » Clean projects selected below » select your project and click OK.
That did the trick for me.
Hope it works for you as well
Update: well actually I might have to retract my opinion.. the actions removed the error messages but now I am missing certain classes and methods... arggghhhh
I just restarted Eclipse, and the error didn't appear anymore!
I had the same problem,and solved it as follows:
First clean all jars; (This problem must because your some jars)
Delete the project;
Reimport project;
Make sure your sdk is right, and project select one sdk version;
(This is my issue to solve the problem) Right click your project, and select "build-path", next select "add Librarys", and add your private jars;
clean-build, the problem has fixed;
I just had the same problem and I tried all of the solutions listed here with no success (I was starting to get annoyed). Then I removed the project from the workspace and then imported it again, and there were no problems!
This happened to me this way,
I have a quite an old project which I had to start working again today. I use 'Universal Image Downloader' library for basically every project where I have to deal with lots of images. So in this old project I had the source files of 'Universal Image Downloader' included to it's 'src' path. Back then I was a newbie and slowly I started developing my own library which could handle every day simple Android development tasks very easily. Obviously I included the 'Universal Image Downloader' to this.
After dusting off the old project today the first thing I did was to reference my library to speed up the development process but as I was trying to debug I ran into the "Conversion to Dalvik format failed with error 1" over and over again. First I thought it was the support library but even after clearing all libraries and adding only mine and doing a quick 'Fix project properties' I still got it. After trying various solutions I noticed this in the console "java.lang.IllegalArgumentException: already added: Lcom/nostra13/universalimageloader/cache/disc/BaseDiscCache;"
It was as simple as that... I'm trying to compile a class which has already been compiled.
Solution : I just simply removed all the class files I got from 'Universal Image Downloader' library from the 'src' directory. Since my library references "Universal Image Downloader" library the old project started working just fine.
Hit same problem shown on your log when trying to run an example project which was imported into eclipse.
Additional Info: in eclipse's Problems View I see the following error:
"The project cannot be built until build path errors are resolved"
In my case the imported project find the libraries just right(by just right I mean I can see the external path to each of the android libs in this case 2 libs, android.jar and maps.jar). So no shuffling of libs in my case, but might be your problem.
I followed Spock's suggestion of cleaning the project which I had to clean multiple times until it somehow resolve its issues. After, issue was solved I had to specify an AVD for the project to run and soon after was up and running on the emulator. Also, note that my eclipse is set up to Build Automatically.
In my case I'm not missing any class files or anything after the clean as the build is properly generating them.
Regards!
I was getting the same error. My problem was that i had an android device hooked up to debug with. As soon as I unplugged it I was able to export.
The answer I found was checking the source and library build path in the project's properties. Most likely there will be a duplicate as in something being referenced in both the source and library tabs. So delete the extra in the source tab and then clean the project and you should be good to go.
Either:
javax.net.SocketLibrary is in your source code, or
javax.net.SocketLibrary is included in a JAR file in your project
Under certain conditions it gets its knickers in a twist and the best fix I've found is to remove referenced jars, clean, add them back in and then compile again.
I believe the error can be caused by including the same classes twice.
This error will also occur (and you won't be able to get rid of it by cleaning) when using classes that are not part of the Android environment.
To summarise the information in the link bimbim.in provided (well my understanding when I glanced over it)
The Android Davik VM tries to compile the jars but finds some stuff that it can't compile to .dex files
so
Just create a "lib" directory in the root of the project (where the src, bin res directories are) and add them to the build path. Project Properties... Java Build Path... Libraries.. Add JARs..
I could resolve this issue by creating a new project, looks like the some project settings were creating this issue and could not really find the root cause for that. But, dumping the existing source code onto the new project resovled this issue. If anyone has found the root cause for this problem pls do let me know.
I had the same problem and solved it as follows:
- Go to Project/Properties/Java Build Path/Libraries and remove all JARs except Android
- Do a project clean
- Add the JARs again as External JARs (first time I added them internally, so that might be the problem)
After that the error was gone.
I solved the problem by updating available packages in the Android SDK et AVD manager. No need to remove Eclipse.
Whenever the Project is having the ambitious data. This problem is caused. May be android can't able to find which one choose.
From what I understand, this same cryptic error could be caused from a wide variety of reasons. I've got "Conversion to Dalvik format failed with error 1" error too. In my case the problem was that for some reason Project -> Properties -> Java Compiler was not set to "Enable project specific settings" with proper Java 1.5 settings, but was left to defaults instead (1.6 in my case). Debug, build and test on devices/emulators worked fine, but export always failed with the above error message.
If unsure about the proper settings, create the same project on some alternative location and just copy all needed files from the old project into the new one. This fixed the issue for me.
The next problem with the same error message came from using proguard. Updating to the latest version by replacing the one that came with android sdk, fixed that.
Hope this helps
My problem was having a jar file in my src folder. Removing jars from the build path works, but only if you don't need the jar in question. For people who need the jar in question, make sure that your jar file is not in the project folder (maybe just src subtree, but I would keep it separate to test). Put it on your desktop or something and try the "Add external jar.." option. Be sure to remove the jar from the project filesystem before adding another external. Having both is what causes the problem.
I have done it as the instruction of the first answer and it works.(Linux)
I think the problem may caused by SDK or ADT updates.
I do have to clear all the lib in Java Building path and then use android tools to fix the project. After cleaning and rebuild, it works as before.

Categories

Resources