Java 发生 JNI 错误,请检查您的安装并在 Eclipse x86 Windows 8.1 中重试

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22381202/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 15:24:53  来源:igfitidea点击:

A JNI error has occurred, please check your installation and try again in Eclipse x86 Windows 8.1

javamysqleclipsejava-native-interface

提问by Jash Parekh

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() {
    // construct components
    form = new JFrame("Sign Up");
    form.getContentPane().setFont(
            new Font("Plantagenet Cherokee", Font.BOLD, 18));
    txtunm = new JTextField(5);
    txtunm.addKeyListener(this);
    txtunm.setBounds(637, 55, 100, 25);
    txtnm = new JTextField(5);
    txtnm.setBounds(637, 228, 100, 25);
    txteml = new JTextField(5);
    txteml.setBounds(637, 264, 100, 25);
    cmdcreate = new JButton("Create Account");
    cmdcreate.setBounds(527, 350, 188, 25);
    txtpass = new JPasswordField(5);
    txtpass.setBounds(637, 91, 100, 25);
    txtpassreg = new JPasswordField(5);
    txtpassreg.setBounds(637, 300, 100, 25);
    cmdok = new JButton("OK");
    cmdok.setBounds(527, 139, 100, 25);
    lblunm = new JLabel("UserName");
    lblunm.setBounds(527, 55, 73, 25);
    lblpass = new JLabel("Password");
    lblpass.setBounds(527, 91, 100, 25);
    lbleml = new JLabel("Email ID");
    lbleml.setBounds(527, 264, 100, 25);
    lblpassreg = new JLabel("Password");
    lblpassreg.setBounds(527, 300, 100, 25);
    lblnm = new JLabel("Full Name");
    lblnm.setBounds(527, 228, 100, 25);

    // form.setResizable(false);

    // adjust size and set layout
    form.setPreferredSize(new Dimension(800, 450));

    form.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    form.getContentPane().setLayout(null);

    // add components
    form.getContentPane().add(txtunm);
    form.getContentPane().add(txtnm);
    form.getContentPane().add(txteml);
    form.getContentPane().add(cmdcreate);
    form.getContentPane().add(txtpass);
    form.getContentPane().add(txtpassreg);
    form.getContentPane().add(cmdok);
    form.getContentPane().add(lblunm);
    form.getContentPane().add(lblpass);
    form.getContentPane().add(lbleml);
    form.getContentPane().add(lblpassreg);
    form.getContentPane().add(lblnm);

    cmdcreate.setActionCommand("Create Account");
    cmdcreate.addActionListener(this);
    cmdok.setActionCommand("Login");

    JPanel panel = new JPanel();
    panel.setBounds(502, 29, 254, 154);
    panel.setFont(new Font("Palatino Linotype", Font.PLAIN, 14));
    panel.setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.RAISED,
            null, null), "LOGIN", TitledBorder.LEADING, TitledBorder.TOP,
            null, null));
    panel.setBackground(SystemColor.controlHighlight);
    form.getContentPane().add(panel);

    panel_1 = new JPanel();
    panel_1.setBounds(500, 204, 254, 186);
    panel_1.setFont(new Font("Palatino Linotype", Font.PLAIN, 14));
    panel_1.setBorder(new TitledBorder(new EtchedBorder(
            EtchedBorder.RAISED, null, null), "SIGN UP",
            TitledBorder.LEADING, TitledBorder.TOP, null, null));
    panel_1.setBackground(SystemColor.controlHighlight);
    form.getContentPane().add(panel_1);

    JLabel lblNewLabel = new JLabel("New label");
    lblNewLabel.setBounds(91, 139, 286, 101);
    lblNewLabel.setIcon(new ImageIcon(
            "C:\Users\JAsh\Desktop\Projects\JAsh.png"));
    form.getContentPane().add(lblNewLabel);

    JPanel panel_2 = new JPanel();
    panel_2.setBounds(77, 118, 315, 145);
    panel_2.setBorder(new EtchedBorder(EtchedBorder.RAISED,
            SystemColor.activeCaptionBorder, SystemColor.menu));
    panel_2.setBackground(SystemColor.controlHighlight);
    form.getContentPane().add(panel_2);
    cmdok.addActionListener(this);

    form.setResizable(false);
    form.pack();
    form.setVisible(true);
    System.out.println("const..");
}

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

@Override
public void actionPerformed(ActionEvent ae) {
    // TODO Auto-generated method stub

    if (ae.getActionCommand().equals("Create Account")) {
        new Registration(txtnm.getText(), txteml.getText(), new String(
                txtpassreg.getPassword()));
        form.setVisible(false);
    }

    if (ae.getActionCommand().equals("Login")) {
        try {
            if (txtunm.getText().equalsIgnoreCase("admin")
                    && new String(txtpass.getPassword()).equals("admin")) {
                form.setVisible(false);
                new Admin();
            } else {
                DataBase db = new DataBase();
                db.connect();
                String sql = "SELECT * FROM LOGIN WHERE USERNAME='"
                        + txtunm.getText() + "'";
                ResultSet rs = db.getDDL(sql);
                boolean found = false;
                while (rs.next()) {
                    if (rs.getString("Password").equals(
                            new String(txtpass.getPassword()))) {
                        found = true;
                        form.setVisible(false);
                        String name = rs.getString("FullName");
                        Session.startSession(txtunm.getText(), name);
                        new FacultyWelcome();
                    }
                }
                if (!found)
                    JOptionPane.showMessageDialog(new JFrame(),
                            "Invalid Credentials");
                db.close();
            }
        } catch (Exception e) {
        }
    }

}

@Override
public void keyPressed(KeyEvent arg0) {
    // TODO Auto-generated method stub
}

@Override
public void keyReleased(KeyEvent arg0) {
    // TODO Auto-generated method stub

}

@Override
public void keyTyped(KeyEvent arg0) {
    // TODO Auto-generated method stub
//  JOptionPane.showMessageDialog(new JFrame(), arg0.getKeyChar()+"-"+arg0.getKeyCode());

}

}

}

The above code works perfectly on my friend's laptop and throws this error on my laptop. I have running the code on Eclipse Juno using Java 7. I have also tested and run a lot java programs on my laptop all works well. This is the only program which gives such an error. This is my final year project and I need it to work on my laptop, I will be greatful to anyone who helps

上面的代码在我朋友的笔记本电脑上运行良好,但在我的笔记本电脑上抛出了这个错误。我已经使用 Java 7 在 Eclipse Juno 上运行了代码。我还在我的笔记本电脑上测试并运行了很多 Java 程序,它们都运行良好。这是唯一出现这种错误的程序。这是我最后一年的项目,我需要它在我的笔记本电脑上工作,我将非常感谢任何有帮助的人

采纳答案by Navid Vafaei

Short answer:Right-click on the class that contains the main method. Click on "Run As". Click on "Java Application". The keyboard shortcut is: Shift+Alt+X J (while holding Shift and Alt, press X; then release Shift and Alt and press J).

简短回答:右键单击包含 main 方法的类。单击“运行方式”。单击“Java 应用程序”。键盘快捷键是:Shift+Alt+XJ(同时按住 Shift 和 Alt,按 X;然后松开 Shift 和 Alt 并按 J)。

Long answer:To be honest, I am not 100% sure why this problem happens. It might be because of using a different jdk. I faced the same error. The solution was easier than I imagined. I was used to running my code using Ctrl + F11. But when I ran it as a java application (the way I described in "short answer"), the problem was resolved. I am not sure if it solves other people's problems as well, but it is worthwhile to try. :)

长答案:老实说,我不是 100% 确定为什么会出现这个问题。可能是因为使用了不同的 jdk。我遇到了同样的错误。解决方案比我想象的要容易。我习惯于使用 Ctrl + F11 运行我的代码。但是当我将它作为 Java 应用程序运行时(我在“简短回答”中描述的方式),问题就解决了。我不确定它是否也解决了其他人的问题,但值得一试。:)

回答by H S Rathore

I faced a similar problem and than got the solution in the package name. I kept the package name as java.basics. In the console I got a hint for that as it clearly said Prohibited package name. So I changed package name and it worked.

我遇到了类似的问题,然后在包名中找到了解决方案。我将包名保留为 java.basics。在控制台中,我得到了一个提示,因为它清楚地说明了禁止的包名称。所以我更改了包名并且它起作用了。

回答by CoDeSigns

I had similar issues when using 'java' at the beginning of the package name, e.g. java.jem.pc

在包名的开头使用“java”时我遇到了类似的问题,例如 java.jem.pc

Check your console output, I was receiving:

检查您的控制台输出,我收到:

Exception in thread "main" java.lang.SecurityException: Prohibited package name: java.jem.pc

回答by Miguel Ormita

You can check the console first to see the actual error message then proceed by looking for answers for that error.

您可以先检查控制台以查看实际的错误消息,然后继续查找该错误的答案。

My console shows the error NoClassDefFound for the class jcommander. Your error will probably be different from mine. The cause of my error is that the class jcommander is not in my M2 repository, so I just have to add that dependency in my pom.xml. You can check if all the class dependencies are all declared and added in your current config and project build.

我的控制台显示类 jcommander 的错误 NoClassDefFound。你的错误可能与我的不同。我的错误的原因是类 jcommander 不在我的 M2 存储库中,所以我只需要在我的 pom.xml 中添加该依赖项。您可以检查所有类依赖项是否都已声明并添加到您当前的配置和项目构建中。

NoClassDefFoundError

NoClassDefFoundError

回答by Devendra

I also faced the same issue. By looking at the console that's saying

我也面临同样的问题。通过查看控制台说

java.lang.SecurityException issue.

java.lang.SecurityException 问题。

the Solution is:

解决方案是:

Check your package name of your project.

检查项目的包名称。

Hope your issue will be resolved. If not, then please print your console trace for tracking the root cause.

希望你的问题能得到解决。如果没有,那么请打印您的控制台跟踪以跟踪根本原因。

回答by erank

It can happen if the JDK version is different.

如果 JDK 版本不同,就会发生这种情况。

try this with maven:

用 Maven 试试这个:

<properties>
    <jdk.version>1.8</jdk.version>
</properties>

under build->plugins:

在构建->插件下:

<plugin>

    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>2.3.2</version>
    <configuration>
        <source>${jdk.version}</source>
        <target>${jdk.version}</target>
    </configuration>

</plugin>

回答by Keshav Bisarwal

Check your console. It says java.lang.SecurityException issue. Change your 'package name'. I changed my package name from 'java.assessment' to 'assesment' and it worked for me. If somebody knows the root cause , let me know please.

检查您的控制台。它说 java.lang.SecurityException 问题。更改您的“包名称”。我将包名从“java.assessment”更改为“assesment”,它对我有用。如果有人知道根本原因,请告诉我。

回答by Bheemashankar Pattar

edit the ".classpath" and include below tag

编辑“.classpath”并包含下面的标签

<classpathentry kind="con" path="org.testng.TESTNG_CONTAINER"/>

<classpathentry kind="con" path="org.testng.TESTNG_CONTAINER"/>

this could solve your problem.

这可以解决您的问题。

回答by user8472395

Error:A JNI error has occurred, please check your installation and try again in Eclipse

Solution:Check your package name as it may be colliding with the package name in java. Simply change the package name to resolve your issue. :)

错误:发生 JNI 错误,请检查您的安装并在 Eclipse 中重试

解决方案:检查您的包名,因为它可能与 java 中的包名冲突。只需更改包名称即可解决您的问题。:)

回答by DvixExtract

In my case the issue was caused by the JDK version. To solve this I suggest to go into your pom file and check the <jdk.version>1.7</jdk.version>.

就我而言,问题是由JDK 版本引起的。为了解决这个问题,我建议进入你的 pom 文件并检查<jdk.version>1.7</jdk.version>.

Afterwards check java version in your cmd(windows) or terminal ( OSX or LINUX ) by typing : java -version.

然后在您的 cmd(windows) 或终端(OSX 或 LINUX)中输入以下命令检查 java 版本:java -version

Compare the version shown in the terminal\command prompt with what you have in your pom file. Make sure they are the same. Then run your project again.

将终端\命令提示符中显示的版本与您在 pom 文件中的版本进行比较。确保它们相同。然后再次运行您的项目。