0

I created a little JFrame program which works fine in IDEA and on my PC in general, the problem is when someone without JDK tries to run my program they get the error:

"A jni error has occurred please check your installation and try again".

I was able to recreate the error by simply moving my JDK to my desktop or somewhere else, but for some reason even reproducing it on my PC does not work.

I am using a normal project in created in IDEA.

I also googled for solutions but wasn't able to find anything that fixes my problem.

EDIT: I already tried to bundle my exe with JRE but it did not work.

EDIT 2: To reproduce this error I wrote this small code:

import javax.swing.*;
import java.net.URISyntaxException;

public class HelloWorld {
    public static void main(String[] args){
        JFrame testframe= new JFrame("test");
        testframe.setSize(100, 100);
        testframe.setVisible(true);
    }
}

After creating a JAR file I used Launch4j to create an executable file. Also made it so it has jre coming with it. If I now send someone else my exe file or move my JDK to my desktop it gives me the previously mentioned error. If someone installs JDK it works fine for him too.

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
Yess
  • 11
  • 2
  • You cannot run a jar without a Java Runtime... if you want to create a standalone executable you'll have to include the whole Java Runtime inside your jar in some way – Giacomo Alzetta Jan 27 '20 at 11:48
  • JDK is requried for development purpose. But if someone just wants to run jar then they only need to install JRE. Not whole JDK. – gprathour Jan 27 '20 at 11:49
  • Are you sure there's no JRE/JDK? I find it strange you could get an error message saying "A JNI error has occurred" if there weren't some Java Runtime present. Try running the code from the command line to see if you get a more helpful error message. – Slaw Jan 27 '20 at 12:03
  • There is an jre, the problem is when I give others my programm with the jre as an executable, they get the error: "A jni error has occurred please check your installation and try again". I get the same error when I move my JDK out of my java folder and then run the exe. @Slaw – Yess Jan 27 '20 at 12:20
  • 1
    Considering I believe JNI stands for "Java Native Interface" I still find it strange a _missing_ JRE/JDK could be the problem. In my experience, that error usually means the main class could not be found, the main class wasn't specified, the wrong Java version is being used, or the application otherwise failed to start (e.g. a `ClassNotFoundException`)—but the JRE/JDK was found. What error do you get when launching from the terminal? Also, you mention "run [your] jar" but then you also mention "bundle [your] exe with JRE". Where is this EXE coming from? How did you create it? A [mre] may help. – Slaw Jan 27 '20 at 12:25
  • @Slaw Gave an example so you can reproduce the error. – Yess Jan 27 '20 at 12:37
  • Does this answer your question? [A JNI error has occurred, please check your installation and try again in Eclipse x86 Windows 8.1](https://stackoverflow.com/questions/22381202/a-jni-error-has-occurred-please-check-your-installation-and-try-again-in-eclips) – Andrey Jan 28 '20 at 06:56

0 Answers0