14

I'm trying to use Simple XML to convert my java objects to XML format in my Android application.

I'm getting NoClassDefFoundError at line

Serializer serializer = new Persister();

java.lang.NoClassDefFoundError: org.simpleframework.xml.core.Persister

I have simple-xml-2.6.1.jar in project class path and when I got NoClassDefFoundError I also put these 3 jars in classpath

stax-1.2.0.jar

stax-api-1.0.1.jar

xpp3-1.1.3_8.jar

but made no use.

Still having NoClassDefFoundError.

Any kind of help will be appreciated.Thank you.

quietmint
  • 13,885
  • 6
  • 48
  • 73
  • The only possible reason is you failed to put simple-xml-2.6.1.jar into the classpath. I checked Persister class , there is not any static block and the constructor is simple. – Clark Bao Aug 29 '11 at 08:45
  • I used [dedexer](http://dedexer.sourceforge.net/) to convert my application's .dex file to .class files and couldn't see org.simpleframework folder.This means simpleXML jar is not being put in my .apk.Thanks for inspiration. –  Aug 29 '11 at 09:58
  • I manually added all source code of simple-xml-2.6.1.jar to my project and I see it's working like that.Trying to find why I can't make it run with the classes from jar file even I add the jar to buildpath of the project. –  Sep 02 '11 at 07:50
  • Perhaps the simple-xml-2.6.1.jar is compiled by a lower version of javac that android is failed to recompile it. – Clark Bao Sep 02 '11 at 08:32
  • This *just* started happening for me, having upgraded the Android SDK and tools, so I guess it's related to javac versions for me. – Matt Gibson Mar 22 '12 at 09:51

6 Answers6

21

Do you have Simple XML checked under "Order and Export" in the Build Path configuration?
I just ran across this problem after updating to the latest SDK and Eclipse plugins for Android, having been successfully using Simple for months.

For some reason, after the update, I had to go and:

  • Check simple-xml-2.6.2.jar under "Order and Export"
  • Clean my project (important)

After those two steps, the problem went away.

Chandra Sekhar
  • 16,256
  • 10
  • 67
  • 90
Matt Gibson
  • 37,886
  • 9
  • 99
  • 128
  • This along with savemaxim's answer did the trick. +1 FOR ALL! :D – Hasani Blackwell May 23 '12 at 03:14
  • @kilonet Not sure what you mean. It's certainly working fine in production for me. Well, the app's sold 5,000 copies on the Play Store, and it wouldn't work without Simple XML, so I'm *assuming* this solution works :D – Matt Gibson Mar 11 '13 at 09:57
6

I resolved same problem like yours modifying Java Build path.

I installed Android DDMS 17.0.0.v201203161636-291853 today and NoClassDefFoundError appeared.

How to fix -> Check check box against simple-xml dependency and give it higher priority than yourproject/src/main/java

enter image description here

savemaxim
  • 377
  • 3
  • 6
2

You don't need those three other jars in your classpath.

Make sure your classpath looks like this and that you puth the jar file in the lib folder (for conventions sake):

project build path

Add the library to the build path

add to build path

Bram Vandenbussche
  • 1,401
  • 11
  • 22
  • I'm having .jar in my classpath.Actually I have it in another project which I use as library project.simple-xml-2-6.jar is included in my project being called from the other project. –  Aug 29 '11 at 09:10
  • 1
    I think it would be wiser to just add the jar to your project's lib folder and then include it in the build path. Not sure why it isn't working when you add the project reference, but that does not seem to be a very portable way of working. – Bram Vandenbussche Aug 29 '11 at 09:22
  • I pulled simpleXML jar from external project and put it in the project it's been used.Situation is the same.I think I'm missing some point.Thanks. –  Aug 29 '11 at 09:40
  • Did you add it to the project classpath? "Right-click the jar file > Add to build path"? I've added a screenshot of this to my answer – Bram Vandenbussche Aug 29 '11 at 09:53
  • If my answer helped you out, can you please select it as the correct answer to the question? It helps other people when searching for this problem. – Bram Vandenbussche Sep 02 '11 at 06:29
  • I just tried your putting jar in the same project so I can tell it gave me some inspiration and I flagged your comment as great comment.Thanks. –  Sep 02 '11 at 06:38
  • But the problem wasn't the same? Can you then elaborate on what whas the problem, and how did you fix it? So if people with the same problem come here, they'll find the correct answer? – Bram Vandenbussche Sep 02 '11 at 06:49
  • No suitable solutions yet,I'm working on it.When I find I'll post it here and let everybody know ok? –  Sep 02 '11 at 06:57
0

It's little strange, but this works for me.

Serializer serializer;        
Persister persiter = new Persister();
serializer = persiter;   
Ashley Medway
  • 7,151
  • 7
  • 49
  • 71
0

you got this error because might be you do not have declare any of your Activity in to the manifest file. So please add it into your manifest file as like below:

 <activity android:name=".DatabaseActivity"></activity>

here DatabaseActivity is my Activity of the application. try it.

Shreyash Mahajan
  • 23,386
  • 35
  • 116
  • 188
  • I think this is a back to basics answer I've already done that description in my manifest.Thanks. –  Aug 29 '11 at 09:03
0

when you deploy your app to your device (or emulator) do you get any errors about the jar that you are trying to include? Not all jars will work on Android. Older code may present a problem You may need to get source and recompile the jar you are interested in. This ensures that the bytecode is compatible with Android. I got this error before with some jars, that said they worked for me even with the errors. They were also xml related (not SimpleXML).

Anthony Nolan
  • 2,338
  • 1
  • 14
  • 12
  • I'll consider that.I've searched a little bit about converting java classes to xml and mostly SimpleXML was suggested to be used.That's why I try to figure out this error.Thanks. –  Aug 29 '11 at 09:12
  • 1
    Hi, I used dom4j and jaxen for this. I wrote code to serialise an object to xml and then send it to my appengine for storage. The reverse worked too. These libraries are simple to use. I am not saying that your chosen library is the problem, but switching to these maybe even temporarily may get you over a hump. – Anthony Nolan Aug 29 '11 at 10:01