I'm encountering an error "A JNI error has occurred

I’m encountering an error “A JNI error has occurred. Please check your installation and try again” when running a Java program in Eclipse on my Windows 8.1 x86 machine. The program, which includes GUI components and database interactions, runs fine on my friend’s laptop.

Here is a simplified version of the Java program that reproduces the error:

public class LoginCumReg implements ActionListener, KeyListener { private JFrame form; private JTextField txtunm; private JTextField txtnm; private JTextField txteml; private JButton cmdcreate; private JPasswordField txtpass; private JPasswordField txtpassreg; private JButton cmdok; private JLabel lblunm; private JLabel lblpass; private JLabel lbleml; private JLabel lblpassreg; private JLabel lblnm; private JPanel panel_1;

public LoginCumReg() {
    // GUI initialization code
    // ...
}

public static void main(String[] args) {
    new LoginCumReg();
}

// ActionListener and KeyListener implementations
// ...

// Database interaction code
// ...

}

The error occurs only on my laptop, even though I’ve successfully run other Java programs on it. How can I resolve this issue?

Hey Priyanka,

You can follow the below-given steps:

Right-click on the class that contains the main method. Then:

  1. Click on “Run As”.
  2. Select “Java Application”.
  3. You can also use the keyboard shortcut: Shift + Alt + X, followed by J (while holding Shift and Alt, press X, then release Shift and Alt, and press J).

Hope this helped :slight_smile:

Hey Ian,

Ensure that the versions of Java and Javac match. You can check the versions by running java -version and javac -version in the command line. Both commands should return the same version.

Note: Solution 1 is a quick fix and has worked for several others. However, it might not work for everyone. Solution 2 is the proper and recommended way to resolve the issue.

@ian-partridge Your short answer was very helpful. I just needed to create a new run configuration in Eclipse, specifying the name of my application and selecting the class containing the main method. It worked perfectly.