Question:
A Java exception has occurred?
anonymous
2014-01-13 09:37:52 UTC
Hello all,

My program was working but today I've decided to add JFreeChart and JCommon to my library and I've set up a button which when clicked displays a bar chart. The problem is when I clean and build the project everything goes smoothly and then when I click the generated .jar file in my netbeans project directory it all shows up fine, but however if I move the .jar file from netbeans directory to my desktop, i get the error 'A java exception has occurred'. I've also tried to run it through CMD and it displays the following:

Exception in thread "main" java.lang.NoClassDefFoundError: org/jfree/data/category/CategoryDataset
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at sun.launcher.LauncherHelper.getMainMethod(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.jfree.data.category.CategoryDataset
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 6 more

Can anyone help me out?

Thanks
Two answers:
MAS
2014-01-13 09:50:04 UTC
Try to export your project as a jar package
anonymous
2014-03-15 08:44:39 UTC
This is very likely a Java classpath problem. Since your Java program also depends on the JFree chart API, you have also to specify these referencing JAR files in your -classpath definition as well. This is why you are getting a NoClassDefFoundError. It means the JVM could not finding the JFree chart class at runtime: org.jfree.data.category.CategoryDataset



Netbeans will include those automatically but when you run it outside you have to do this manually.



Add these libraries to your Java start-up command (-classpath argument) and see if this resolves your problem.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...