0

I'm working on a project in java that's supposed to let the user type in a bunch of data. The data typed in is then going to be handled by the program so that it can be graphically shown to the user. Once the data is typed in I want there to be a "save" button, mainly because I want to give the user the opportunity to continue his/her work later. So after doing some reading on how to save data in a java program, I thought it'd be a good idea to use XStream and save the data as an XML-file.

So, my problem now is that I can't make my program find the XStream package. I have downloaded the XStream folder containing a bunch of .jar files and tried putting them in the same folder as my own .java files and in the main program writing: import com.thoughtworks.xstream.XStream;

This works fine when I compile, but when I run the program, this error shows up:

Exception in thread "main" java.lang.NoClassDefFoundError: org/xmlpull/v1/XmlPullParserException

So what I need help with is how I can get my program to import the classes from the jar files that I need. Where should I put the jar files? I'm a beginner to Java and I'm not writing my code in and IDE, I'm writing it in Smultron on my Mac.

Thanks in advance

  • It looks like a classpath problem, how do you run your program? Try having a look at here (http://www.coderanch.com/t/521804/java/java/classpath-current-directory). If I were in you I'd use an IDE like Eclipse it lets you concentrate on the programming leaving aside problem like this. – Maxx Jun 25 '12 at 09:44
  • I run the program in the command prompt. Hm, ok, I'll give Eclipse a go. I've been avoiding it for as long as possible now but I guess it's helpful when it comes to things like this. – user1479445 Jun 25 '12 at 09:58

1 Answers1

0

For start, Eclipse is a great IDE and I strongly recommend it.

Now for your question: This error means that one of the classes in your application is using the class 'org/xmlpull/v1/XmlPullParserException' but it cannot find it in the classpath, so you need to find the jar that contains this class (you can use Total Commander for that) and then add it to the classpath when running the program by adding the '-cp' flag:

java -jar myapp.jar -cp otherjar.jar
Tomer
  • 17,787
  • 15
  • 78
  • 137