Application only works in Eclipse - java

I'm doing a college project using Java and Eclipse. The app works perfectly in Eclipse, but when I export it as Runnable Java File it doesn't work. No any error is shown, and nothing is opened.
Do you have any tutorial about how to export it correctly? The application is too long to post here. However, if you need to see any part of code just ask.
EDIT : Error returned by console
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoa
der.java:58)
Caused by: java.lang.ClassCastException: sun.net.www.protocol.jar.JarURLConnecti
on$JarURLInputStream cannot be cast to java.io.BufferedInputStream

Here is one good article on jar creation and execution http://javarevisited.blogspot.in/2012/03/how-to-create-and-execute-jar-file-in.html

I've solved the problem! I don't know why, but It was caused by BufferedInputStream so I changed it by InputStream and the application works perfectly, thanks everybody!

Related

Java NoSuchMethodError for regex.Matcher.results() when running .jar file

When I run my app as a .jar file, it returns the below error:
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrc
der.java:61)
Caused by: java.lang.NoSuchMethodError: java.util.regex.Matcher.results()Ljav
til/stream/Stream;
at SalesToExcel.start(SalesToExcel.java:108)
at SalesToExcel.main(SalesToExcel.java:45)
... 5 more
However, it works when I run it inside of the Eclipse IDE. Any ideas? I'm not sure if I'm somehow missing a proper jar file even though java.utils.regex should come included in rt.jar. Is there a way to check if this is missing somehow when I package the jar?
So, this is your problem. java.util.regex.Matcher.results is in Java since Java 9 and you are running the .jar with Java 8.
Eclipse runs with Java11.
Install as default JRE at least Java9 in your OS (Windows ?).

Eclipse no reasons errors

i have been using eclipse, mars, neon and oxygen and i always had the same problem after some days/weeks of using its.
When i press run. It sometimes likes not to work and with no reason scream
Error: Could not find or load main class test.PingSwitchPing
and sometimes after i press run a few more times it suddenly works...
other times when i make some changes to code eclipse doesn't compile to make changes and run old code...
this time it is giving me something that it can't even replicate right now so i cant show error message, but basically the error was about not seeing class path to external libraries and to other parts of code that where in diffrent folder. While it was in phase on loading javafx application.
Why is it so unstable ? it is really piss me off becouse sometimes i am loosing hours to fight with it...
Sometimes i remove .m2 folder and redonwload everyting and it is helping. Cleaning project do nothing to this.
Sometimes restarting pc and eclipse works other times it dosen't...
I was just writing that i can't replicate main error but when i changed on line of code and run then it occurs. When i change it back nothing change. it still dosent work and dont want to work...
Exception in thread "JavaFX Application Thread" Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
Caused by: java.lang.NullPointerException
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:383)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
... 5 more
java.lang.NoClassDefFoundError: org/quartz/SchedulerException
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplicationWithArgs$155(LauncherImpl.java:352)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.quartz.SchedulerException
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)
... 11 more
It once even let me write this
scene.getStylesheets().add("My.css");
and it worked event when this file was in .../workspace
when project was in .../workspace/MavenProjectName
It is just so unrelabile...

Exporting Applications with Databases to Executable Jar in Netbeans

I'm building a desktop application with an Apache Derby database. When I run the application from Netbeans, it works fine, but when I run the application's executable jar file, I get a "java.lang.ExceptionInInitializerError" "Caused by: java.lang.IllegalStateException: Attempting to execute an operation on a closed EntityManager."
The jar file was created by right-clicking the project in Netbeans, and clicking "Clean and Build".
I've looked at the the following resources, but the information wasn't applicable:
Export JAR with Netbeans
https://netbeans.org/kb/articles/javase-deploy.html
This is my first time using Derby, so it's probably something simple that I'm missing.
Stack trace:
java.lang.ExceptionInInitializerError
at myProject.Main.start(Main.java:70)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(Unknown Source)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$11(Unknown Source)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$9(Unknown Source)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(Unknown Source)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(Unknown Source)
at java.base/java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalStateException: Attempting to execute an operation on a closed EntityManager.
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.verifyOpenWithSetRollbackOnly(EntityManagerImpl.java:1923)
at org.eclipse.persistence.internal.jpa.QueryImpl.getSingleResult(QueryImpl.java:508)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.getSingleResult(EJBQueryImpl.java:400)
at graphics.view.Read.<clinit>(Read.java:50)
... 10 more
As it turns out, I made a (very) silly mistake in my code. I closed the EntityManager that I made the query on in the line before I called getSingleResult() on my query. I'm not quite sure why the program worked when I ran it from Netbeans, but the problem is solved now.

First Java Program - Exception in thread "main" java.lang.NoClassDefFoundError

After creating a number of Android apps using Java in Eclipse. I now need to create a stand alone Java program so that I can create an sqlite database - that will eventually be used in a future Android app.
I am using the SQLJet library from http://sqljet.com and have copied their example code.
When I try to run the code by using the "Run" button in Eclipse I get the following error.
Exception in thread "main" java.lang.NoClassDefFoundError: org/antlr/runtime/RecognitionException
at org.tmatesoft.sqljet.core.table.engine.SqlJetEngine$2.runSynchronized(SqlJetEngine.java:282)
at org.tmatesoft.sqljet.core.table.engine.SqlJetEngine.runSynchronized(SqlJetEngine.java:217)
at org.tmatesoft.sqljet.core.table.engine.SqlJetEngine.readSchema(SqlJetEngine.java:276)
at org.tmatesoft.sqljet.core.table.engine.SqlJetEngine.getOptions(SqlJetEngine.java:299)
at nlmc.loader.apps4care.com.Test.main(Test.java:36)
Caused by: java.lang.ClassNotFoundException: org.antlr.runtime.RecognitionException
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)
... 5 more
Now as the code has been copied without change, I am guessing there is nothing wrong with that and I suspect that I don't have my environment set up correctly. As a newbie Java developer (normally C#) I'm struggling to make sense of what the problem is. never mind the solution.
Code now working and the database is created. Unfortunately looks like it is not compatible with the sqlite3, the version Android uses. Back to the drawing board...!
The program needs the class org.antlr.runtime.RecognitionException. See here for a list of jars where you can find it: http://www.jarfinder.com/index.php/java/info/org.antlr.runtime.RecognitionException
EDIT: And here you can see all the dependencies for SQLJet: http://mvnrepository.com/artifact/org.tmatesoft.sqljet/sqljet/1.1.1

UnsatisifiedLinkError - Any idea on how to fix this?

Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: com.melloware.jintellitype.JIntellitypeException: Could not load JIntellitype.dll from local file system or from inside JAR
at com.melloware.jintellitype.JIntellitype.<init>(JIntellitype.java:114)
at com.melloware.jintellitype.JIntellitype.getInstance(JIntellitype.java:174)
at CaptureScreen.registerHotkeys(CaptureScreen.java:163)
at CaptureScreen.<init>(CaptureScreen.java:100)
at CaptureScreen.main(CaptureScreen.java:199)
... 5 more
Caused by: java.lang.UnsatisfiedLinkError: C:\Users\B\AppData\Local\Temp: Can't find dependent libraries
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(Unknown Source)
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.load0(Unknown Source)
at java.lang.System.load(Unknown Source)
at com.melloware.jintellitype.JIntellitype.<init>(JIntellitype.java:99)
... 9 more
I get this error when I run from the command line, however, it does not cause any issues with my program running on my machine, however, on other peoples machines the program will not run at all.
I have never come across this error before and fairly confused.. mostly that it runs fine on my machine, but not on others even though it throws this error on both.
This is a classpath error. Its likely that you have it set up right for compile time but not runtime. Make sure that either your jar is in the right location and/or that you've set your classpath to include the jar.
Go to the Jintellitype website, download the source, add it to your download folder and then move the .dll files into the folder with the Jitellitype classes after building the project

Categories