0

My program works fine in both eclipse and netbeans.

But after I clean and build in netbeans, or export as jar file in eclipse, the .jar file got an error.

Here is the code:

Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: org/jfree/data/xy/XYDataset
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: org.jfree.data.xy.XYDataset
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 7 more

I have added all the paths of the library to manifest, still error.

The only way it works is to use eclipse and export it to runnable jar file.

My program will take an int or string (stock code) that users input in the textfeild then it will generate an url to download a csv file to get data and graph. The runnable jar file can works well and generate graph when the stock code that is inputted by the user is a string, but when the user input an int, it can't plot the graph. Why is it having problems with the ints, it works well in eclipse and netbeans and I don't have console to see if there is a error code of the jar file.

thanks for advice!

newbimyth
  • 55
  • 10
  • Possible duplicate of [How to resolve this JNI error when trying to run LWJGL "Hello World"?](http://stackoverflow.com/questions/28922512/how-to-resolve-this-jni-error-when-trying-to-run-lwjgl-hello-world) – Srikanth Balaji Jan 13 '17 at 02:13
  • @SrikanthA I have done that already but still getting the error message – newbimyth Jan 13 '17 at 16:40

1 Answers1

0

It would be usefull if you can explain how you are compiling the jar.. the problem is because you are not including the external libraries inside your jar. You could try one of the following ways if you have the external library

http://javarevisited.blogspot.com/2012/10/5-ways-to-add-multiple-jar-to-classpath-java.html

hlagos
  • 7,690
  • 3
  • 23
  • 41
  • I think you need jfreechart-x.x.x.jar & jcommon-x.x.x.jar in your classpath when attempting run from your application jar file. – Velusamy Velu Jan 13 '17 at 02:44
  • I have already included all the libraries in the project and I think it will be including inside my jar. As I mentioned I already try putting the class paths of the libraries to the manifest file. Is there any other possible ways to fix it? – newbimyth Jan 13 '17 at 04:55
  • 1) just double click it and runs with jar launcher. Than an error message pops out so i use method 2 to run it and see the error message – newbimyth Jan 13 '17 at 16:32
  • 2)go to terminal and run java -jar XXX.jar then it give me the error message that i put in the question – newbimyth Jan 13 '17 at 16:34
  • try something like java -classpath "/full/path/to/lib/folders/*" -jar /path/to/jar/XXX.jar package.example.Main – hlagos Jan 13 '17 at 17:12
  • @lake as using eclipse's runnable jar file solution is what I found usable, but I still want to know what is wrong, for the advice that you told me to try, my jar file is under the src file and I try the full path to lib folders one too, but normal export still doesn't work. – newbimyth Jan 22 '17 at 07:24