简体   繁体   English

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

[英]Error "A JNI error has occurred. Please check your installation and try again in Eclipse x86 Windows 8.1"

Consider:考虑:

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 v4.2 (Juno) using Java 7.我已经使用 Java 7 在Eclipse v4.2 (Juno) 上运行代码。

I have also tested and run a lot of Java programs on my laptop all works well.我还在我的笔记本电脑上测试并运行了很多 Java 程序,都运行良好。 This is the only program which gives such an error.这是唯一给出此类错误的程序。

How can I fix this problem?我该如何解决这个问题?

I have been having this problem for a while, but now I have figured it out.我一直有这个问题,但现在我已经弄清楚了。

It turns out that Java JDK 12 has both the JRE and the JDK inside the bin folder of the Java 12 JDK.事实证明,Java JDK 12 在 Java 12 JDK 的bin文件夹中同时包含 JRE 和 JDK。 (I have always believed that JRE and JDK are different application, but it turns out things have changed.) (我一直认为 JRE 和 JDK 是不同的应用程序,但事实证明情况发生了变化。)

My problem was that I had Java JDK 12 installed on my computer.我的问题是我的计算机上安装了 Java JDK 12。 At the same time, I had Java 8 (JRE) Installed on my computer.同时,我的计算机上安装了 Java 8 (JRE)。 So my computer was getting confused.所以我的电脑变得混乱。

With my command prompt environment set up to run Java and Javac commands:将我的命令提示符环境设置为运行 Java 和 Javac 命令:

I typed the follow commands:我输入了以下命令:

java -version

This gave me Java 8.这给了我 Java 8。

After that, I typed:之后,我输入:

javac -version

This gave me Java 12.这给了我 Java 12。

In other words, my program is getting compiled with Java 12 and I am trying to run with Java 8.换句话说,我的程序正在使用 Java 12 编译,而我正在尝试使用 Java 8 运行。

To solve the problem, I uninstalled Java 8 JRE from my computer.为了解决这个问题,我从我的计算机上卸载了 Java 8 JRE。

I went back to command prompt to check if "java -version" and "javac -version" was returning the same version number, and yes, it was returning Java 12.我回到命令提示符检查“java -version”和“javac -version”是否返回相同的版本号,是的,它返回的是 Java 12。

I tried recompiling my program again, and running it.我尝试再次重新编译我的程序并运行它。 It worked!!有效!!

Solution 1: Right-click on the class that contains the main method.解决方案1:右键单击包含main方法的类。 Click on "Run As".点击“运行方式”。 Click on "Java Application".单击“Java 应用程序”。 The keyboard shortcut is: Shift + Alt + X , J (while holding Shift and Alt , press X ; then release Shift and Alt and press J ).键盘快捷键是: Shift + Alt + XJ (在按住ShiftAlt的同时按X ;然后松开ShiftAlt并按J )。

Solution 2: As Professor mentioned , please make sure that java -version and javac -version are the same.解决方案2:教授所说,请确保java -versionjavac -version相同。

Note: Solution 1 is a quick fix and worked for me and a few other people.注意:解决方案 1 是一种快速修复,对我和其他一些人有用。 It may or may not work for you.它可能适合您,也可能不适合您。 I think Solution 2 is the proper way to solve it.我认为解决方案2是解决它的正确方法。

Running the jar from command line by:通过以下方式从命令行运行 jar:

C:\folder\where\jar\stored>java -jar JarName.jar

I got information which made the problem clearer:我得到了使问题更清楚的信息:

main/Main has been compiled by a more recent version of the Java Runtime main/Main 已由 Java 运行时的更新版本编译

在此处输入图像描述

In this case, the jar was compiled with a version newer than jre supports.在这种情况下,jar 是使用比 jre 支持的版本更新的版本编译的。

Error: A JNI error has occurred, please check your installation and try again in Eclipse错误:发生 JNI 错误,请检查您的安装并在 Eclipse 中重试

Solution: Check your package name as it may be colliding with the package name in Java.解决方案:检查您的包名,因为它可能与 Java 中的包名冲突。 Simply change the package name to resolve your issue.只需更改包名称即可解决您的问题。 :) :)

I solved it by changing my 'Compiler compliance level'.我通过更改我的“编译器合规性级别”解决了这个问题。 In Eclipse:在 Eclipse 中:

Menu WindowPreferencesJavaCompiler .菜单窗口首选项Java编译器

I had similar issues when using 'java' at the beginning of the package name, eg 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

I faced a similar problem with a project, in IntelliJ with Maven dependencies.我在一个项目中遇到了类似的问题,在IntelliJ中具有Maven依赖项。

I solved it changing the dependencies scope from provided to compile.我解决了将依赖范围从提供更改为编译的问题。

IntelliJ :智能

Menu → FileProject structureModulesDependencies → *Scope (provide to) → Compile . Menu → FileProject structureModulesDependencies → *Scope (provide to) → Compile

In my case the issue was caused by the JDK version .就我而言,问题是由JDK version引起的。 To solve this I suggest to go into yourPOM file and check the <jdk.version>1.7</jdk.version>.为了解决这个问题,我建议进入您的POM文件并检查<jdk.version>1.7</jdk.version>.

Afterwards, check the Java version in your cmd (Windows) or terminal (OS X or Linux) by typing: java -version .然后,通过键入: java -version在您的cmd (Windows) 或终端(OS X 或 Linux)中检查 Java 版本。

Compare the version shown in the terminal/command prompt with what you have in your POM file.将终端/命令提示符中显示的版本与您的 POM 文件中的版本进行比较。 Make sure they are the same.确保它们相同。 Then run your project again.然后再次运行您的项目。

You can check the console first to see the actual error message and then proceed by looking for answers for that error.您可以先检查控制台以查看实际的错误消息,然后继续寻找该错误的答案。

My console shows the error NoClassDefFound for the class jcommander .我的控制台显示类jcommander的错误 NoClassDefFound 。

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 file.我的错误的原因是类jcommander不在我的 M2 存储库中,所以我只需在我的pom.xml文件中添加该依赖项。 You can check if all the class dependencies are all declared and added in your current configuration and project build.您可以检查是否所有类依赖项都已声明并添加到当前配置和项目构建中。

NoClassDefFoundError NoClassDefFoundError

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.解决方案是:检查项目的包名称。

It can happen if the JDK version is different.如果 JDK 版本不同,可能会发生这种情况。

Try this with Maven :Maven试试这个:

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

under Buildplugins :Buildplugins下:

<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>

I was facing the same issue and in my case the compiler compliance level was selected as 14 in my Eclipse settings.我遇到了同样的问题,在我的情况下,编译器合规级别在我的 Eclipse 设置中被选为 14。 In order to fix it, I changed it to the version of JDK on my machine ie 1.8 and recompiled the project.为了修复它,我将其更改为我机器上的 JDK 版本,即 1.8 并重新编译了项目。

在此处输入图像描述

Check your console.检查您的控制台。 It says java.lang.SecurityException issue.它说 java.lang.SecurityException 问题。 Change your 'package name'.更改您的“包名称”。 I changed my package name from 'java.assessment' to 'assesment' and it worked for me.我将包名称从“java.assessment”更改为“assesment”,它对我有用。 If somebody knows the root cause , let me know please.如果有人知道根本原因,请告诉我。

I have found that adding these lines of code to the pom.xml file of a Maven project solves similar issues for me:我发现将这些代码行添加到Maven项目的pom.xml文件可以为我解决类似的问题:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>com.packagename.MainClassName</mainClass>
                    </manifest>
                </archive>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>2.3</version>
            <configuration>
                <createDependencyReducedPom>false</createDependencyReducedPom>
            </configuration>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

I faced a similar problem and then got the solution in the package name.我遇到了类似的问题,然后在包名中得到了解决方案。

I kept the package name as java.basics .我将包名称保留为java.basics In the console I got a hint for that as it clearly said "Prohibited package name".在控制台中,我得到了一个提示,因为它清楚地表示“禁止的包名称”。 So I changed the package name and it worked.所以我更改了包名称并且它起作用了。

Possible solution可能的解决方案

If none of these solutions worked for you then try this... I finally got mine working by deleting the two folders ".metadata" and ".recommenders" in the workspace folder.如果这些解决方案都不适合你,那么试试这个......我终于通过删除工作区文件夹中的两个文件夹“.metadata”和“.recommenders”来开始工作了。

You can find your workspace folder path by clicking on menu FileSwitch WorkspaceOther in the Eclipse application's toolbar.您可以通过单击 Eclipse 应用程序工具栏中的菜单FileSwitch WorkspaceOther来找到您的工作区文件夹路径。

Now I am a complete noob crying my way through an software engineering degree at San Jose State University.现在,我是一个彻头彻尾的菜鸟,正在圣何塞州立大学攻读软件工程学位。 So I am just sharing what worked for me without knowing much knowledge of why exactly.所以我只是在不知道确切原因的情况下分享对我有用的东西。

I do not know what harm or headaches, or even if both aforementioned folders needed to be deleted.我不知道有什么危害或头痛,或者即使上述两个文件夹都需要删除。 But in the end, it worked for me and it seems the application just recreates fresh versions of those folders anyway.但最后,它对我有用,而且似乎应用程序只是重新创建了这些文件夹的新版本。

I experienced the same issue, however in my case it was due to the Configuration settings in IntelliJ IDEA.我遇到了同样的问题,但在我的情况下,这是由于 IntelliJ IDEA 中的配置设置造成的。

Even though the project SDK (File -> Project Structure) was set to Java 11, the JRE in the Run/Debug Configurations (Run -> Edit Configurations) was set to Java 8. After changing that to Java 11, it worked like a charm.即使项目 SDK(文件 -> 项目结构)设置为 Java 11,运行/调试配置(运行 -> 编辑配置)中的 JRE 也设置为 Java 8。将其更改为 Java 11 后,它就像一个魅力。

Just check small step...只需检查小步骤...

javac -version

javac 17

java -version

java version "17" 2021-09-14 LTS

Both javac and java versions are the same. javacjava版本都是一样的。 If different, you will get this error.如果不同,您将收到此错误。

Edit the ".classpath" and include the below tag:编辑“.classpath”并包含以下标签:

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

This could solve your problem.这可以解决你的问题。

In my project I had changed my MavenPOM file and removed the entry for maven-jar-plugin.在我的项目中,我更改了我的 MavenPOM文件并删除了 maven-jar-plugin 的条目。

When you build a JAR file whose purpose is to be executable, you need to include this so that certain entries get written into the manifest.当您构建一个目的是可执行的 JAR 文件时,您需要包含它,以便将某些条目写入清单中。 I opened the old project, copied that entry (with some modifications for project name) and it worked.我打开了旧项目,复制了该条目(对项目名称进行了一些修改)并且它起作用了。

I think this happens because the name of your class is the same name of another class in the JDK.我认为这是因为您的类的名称与 JDK 中另一个类的名称相同。 Help Eclipse to determine which one you are trying to run by selecting the package your class is in. Go to run configuration , select the project and the main class .通过选择您的类所在的包来帮助Eclipse确定您正在尝试运行哪一个。转到运行配置,选择项目和主类

When you press the search button to select the main class, you will find options that have the same name but different package , select your class.当您按下搜索按钮选择主类时,您会找到名称相同但包不同的选项,请选择您的类。

My issue came from trying to disable the Maven nature from my project and then deleting the pom.xml file.我的问题来自于尝试从我的项目中禁用 Maven 特性,然后删除pom.xml文件。 This is bad, very bad, don't do this.这很糟糕,非常糟糕,不要这样做。 If you do, change it back to a Maven project and hopefully you can either restore your old pom.xml file or create a new one.如果这样做,请将其更改回 Maven 项目,希望您可以恢复旧的pom.xml文件或创建一个新文件。 As soon as I did that, it worked again.一旦我这样做了,它就再次起作用了。

EDIT: I recently ran across this problem again and this time it was because I had duplicate libraries in my classpath.编辑:我最近再次遇到了这个问题,这次是因为我的类路径中有重复的库。 The one Maven added (which started with /M2_REPO/.... and then one I had added (which I should not have done). Even though Eclipse was reporting that it could not find the class, the actual problem was that I had given it two libraries with the same class and it didn't know which one to use. Once I removed the second reference, it worked. Maven 添加的一个(以 /M2_REPO/.... 开头,然后是我添加的一个(我不应该这样做)。即使 Eclipse 报告它找不到类,实际问题是我有给它两个具有相同类的库,它不知道要使用哪一个。一旦我删除了第二个引用,它就起作用了。

There was no information in my console so that sent me searching for additional solutions and found these - unique to the solutions presented here.我的控制台中没有任何信息,因此让我搜索其他解决方案并找到了这些 - 此处提供的解决方案是独一无二的。 I encountered this with Eclipse v4.7 (Oxygen) trying to run an old Ant build on a project.我在Eclipse v4.7 (Oxygen) 尝试在项目上运行旧的Ant构建时遇到了这个问题。

Cause 1原因1

I had configured Eclipse to use an external Ant install which was version 1.10.2 which apparently had classes in it that were compiled with JDK 9. In Eclipse I got the JNI error described above (running the Ant build at the command line gave me the renowned 'unsupported major.minor version' error - the Java I was using on the system was JDK 8).我已将 Eclipse 配置为使用版本 1.10.2 的外部 Ant 安装,其中显然包含使用 JDK 9 编译的类。在 Eclipse 中,我得到了上述JNI错误(在命令行运行 Ant 构建给了我著名的“不支持的major.minor 版本”错误——我在系统上使用的Java 是JDK 8)。

The solution was to roll back to the embedded Eclipse version of Ant being 1.10.1.解决方案是回滚到 Ant 的嵌入式 Eclipse 版本 1.10.1。 I verified this as the correct solution by downloading Ant 1.10.1 separately and reconfiguring Eclipse to use the new 1.10.1 externally and it still worked.我通过单独下载 Ant 1.10.1 并重新配置 Eclipse 以在外部使用新的 1.10.1 来验证这是正确的解决方案,它仍然有效。

Cause 2原因2

This can also happen when you have the Ant Runtime settings configured incorrectly in Eclipse's Preferences.当您在 Eclipse 的 Preferences 中错误地配置了 Ant Runtime 设置时,也会发生这种情况。 Depending on the version of Ant you're running you will need to add the tools.jar file from the appropriate JDK to the classpath used for the Ant Runtime (Home Entries).根据您运行的 Ant 版本,您需要将tools.jar文件从适当的 JDK 添加到用于 Ant 运行时(主条目)的类路径中。 More specifically, without a proper configuration, Eclipse will complain when launching an Ant target that the JRE version is less than a particular required version.更具体地说,如果没有适当的配置,Eclipse 会在启动 Ant 目标时抱怨JRE版本低于特定要求的版本。

Essentially, 'proper configuration' means aligning each of the configuration items in Eclipse for running Ant so that they all work together.从本质上讲,“正确配置”意味着调整 Eclipse 中的每个配置项以运行 Ant,以便它们一起工作。 This involves the Ant Runtime Home entry (must point to an Ant version that is compatible with your chosen JDK -- you can't run Ant with JDK 8 when it was compiled against JDK 9);这涉及Ant Runtime Home条目(必须指向与您选择的 JDK 兼容的 Ant 版本——当针对 JDK 9 编译时,您不能使用 JDK 8 运行 Ant); specifying the tools.jar that belongs to the JDK you want to run Ant with in the Ant Runtime settings;在 Ant Runtime 设置中指定属于要运行 Ant 的 JDK 的tools.jar and lastly setting the JRE environment of your build script to the JDK you want to run Ant with in the External Tools Configuration.最后将构建脚本的 JRE 环境设置为要在外部工具配置中运行 Ant 的 JDK。

All three of these settings need to agree to avoid the error described above.所有这三个设置都需要同意以避免上述错误。 You'll also need to consider the attributes used in your javac tag to ensure the JDK you're using is capable of executing as you've directed (ie, JDK 7 can't compile code using source and target version 8).您还需要考虑javac标记中使用的属性,以确保您使用的 JDK 能够按照您的指示执行(即,JDK 7 无法使用源和目标版本 8 编译代码)。

Moreover而且

If you're really just trying to run an Ant build script to compile code to an older JDK (eg, less than 8 for Oxygen), this article helped gain access to run Ant against an older JDK .如果您真的只是想运行一个 Ant 构建脚本来将代码编译到较旧的 JDK(例如,对于 Oxygen,少于 8 个),那么本文有助于获得针对较旧 JDK 运行 Ant 的访问权限。 There are Ant plugin replacements for a handful of versions of Eclipse, the instructions are brief and getting the correct plugin version for your particular Eclipse is important.有少数 Eclipse 版本的 Ant 插件替换,说明很简短,为您的特定 Eclipse 获取正确的插件版本很重要。

Or more simply you can use this very good solution to do your legacy compile which doesn't require replacing your Eclipse plugin, but instead changing the javac tag in your build script (while using the latest JDK).或者更简单地说,您可以使用这个非常好的解决方案来进行旧版编译,这不需要替换您的 Eclipse 插件,而是更改构建脚本中的javac标记(同时使用最新的 JDK)。

I have been running into the same error when I adding the following Maven dependency in my project:在我的项目中添加以下Maven依赖项时,我遇到了同样的错误:

<artifactId>aws-encryption-sdk-java</artifactId>

The error came up only when I ran the shade JAR file produced by maven-shade-plugin .仅当我运行由maven-shade-plugin生成的阴影 JAR 文件时才出现错误。 I was able to overcome the error by using the JAR file produced by maven-assembly-plugin .通过使用maven-assembly-plugin生成的 JAR 文件,我能够克服该错误。

一切都不适合我,但是一旦我删除工作区的“.metadata”和“.recommenders”,删除“bin”和“setting”文件夹,然后在我重新导入同一个项目后,它就对我有用.

I faced the same issue in NetBeans 8.0.2.我在 NetBeans 8.0.2 中遇到了同样的问题。 Clean and Build Project solved this problem. Clean and Build Project解决了这个问题。

You can try: right click on the project and then click clean.您可以尝试:右键单击该项目,然后单击清理。 After this run the project.在此之后运行项目。

It works for me.这个对我有用。

The programs which has been written on one version of JDK won't support the JNI platform of another version of the JDK.在一个版本的 JDK 上编写的程序将不支持另一个版本的 JDK 的JNI平台。

If in case we are using JDK 10 and JDK 8 with Eclipse configured for JDK 10 and code written on JDK 10. Now, I don't want to use JDK 10 and started using JDK 8 as jvm and tried to run the code which is written on JDK 10, so Eclipse will threw an error of JNI.如果我们使用 JDK 10 和 JDK 8 以及为 JDK 10 配置的 Eclipse 和在 JDK 10 上编写的代码。现在,我不想使用 JDK 10 并开始使用 JDK 8 作为 jvm 并尝试运行代码写在 JDK 10 上,所以 Eclipse 会抛出 JNI 的错误。

So, to come out of this error, please add the current JVM path to eclipse.ini file.所以,要摆脱这个错误,请将当前的 JVM 路径添加到eclipse.ini文件中。 After this, copy the written code to the clipboard.在此之后,将编写的代码复制到剪贴板。 Delete the project in Eclipse, create a new project, check in the copied code, and run.在Eclipse中删除项目,新建项目,签入复制的代码,运行。

If the problem occurs while launching Ant , check your Ant home: it must point to the same Eclipse folder you are running.如果在启动Ant时出现问题,请检查您的 Ant 主目录:它必须指向您正在运行的同一个 Eclipse 文件夹。

It happened to me while I reinstalled a new Eclipse version and deleted the previous Eclipse folder while keeping the previous Ant home: Ant simply did not find any Java library.当我重新安装一个新的 Eclipse 版本并删除以前的 Eclipse 文件夹同时保留以前的 Ant 主页时,它发生在我身上:Ant 根本没有找到任何 Java 库。

In this case the reason is not a bad JDK version.在这种情况下,原因不是 JDK 版本不好。

I have faced the same issue due to the packaged name being "Java".由于打包名称为“Java”,我遇到了同样的问题。 After renaming the package, it was no longer throwing an error.重命名包后,它不再抛出错误。

In my case, Eclipse was giving me this error, but I was getting classnotfoundexception on javax.servlet.http.HttpServlet in the logs.就我而言,Eclipse 给了我这个错误,但是我在日志中的javax.servlet.http.HttpServlet上得到了classnotfoundexception

In my case, I was trying to start a Spring Boot application with exclude module: 'spring-boot-starter-tomcat' in my build.gradle file (since I'm deploying on WildFly ).就我而言,我试图在我的build.gradle文件中使用exclude module: 'spring-boot-starter-tomcat'启动一个Spring Boot应用程序(因为我在WildFly上进行部署)。

The solution was to comment this exclude out.解决方案是将此排除注释掉。 The Eclipse JNI error was very misleading and I would suggest fixing this. Eclipse JNI错误非常具有误导性,我建议修复此问题。

I had the same issue.我遇到过同样的问题。 I had imported a newer version of a JSON library (I deleted the old one, but I did not remove it from the build path).我导入了一个较新版本的 JSON 库(我删除了旧版本,但我没有从构建路径中删除它)。

I resolved it by removing the reference to the old one from the build path.我通过从构建路径中删除对旧的引用来解决它。

Using Gradle , the following also worked for me:使用Gradle ,以下内容也对我有用:

Package Explorer → right-click project → GradleRefresh Gradle Project .包资源管理器→ 右键单击​​项目 → Gradle刷新 Gradle Project

When we get this error while running our Java application, check if we have some class name or package names starting with ”java.”.当我们在运行 Java 应用程序时遇到此错误时,请检查我们是否有一些以“java.”开头的类名或包名。 If so, change the package name.如果是这样,请更改包名称。

This is happening because your package name is colliding with Java system file names.发生这种情况是因为您的包名与 Java 系统文件名冲突。

Error/Issue:错误/问题:

While trying to run my application as a Java application or as a Spring Boot application, I am getting below error尝试将我的应用程序作为 Java 应用程序或Spring Boot应用程序运行时,出现以下错误

A JNI error has occurred, please check your installation and try again.发生 JNI 错误,请检查您的安装并重试。 A Java exception has occurred.发生Java异常。

As well as getting this error in the console:以及在控制台中收到此错误:

Exception in thread "main" java.lang.UnsupportedClassVersionError: com/example/demo/IocApplication has been compiled by a more recent version of the Java Runtime (class file version 55.0).线程“主”java.lang.UnsupportedClassVersionError 中的异常:com/example/demo/IocApplication 已由 Java 运行时的更新版本(类文件版本 55.0)编译。 This version of the Java Runtime only recognizes class file versions up to 52.0`此版本的 Java 运行时仅识别最高 52.0 的类文件版本

What is the root cause?根本原因是什么?

The reason for this error is that这个错误的原因是

  • the code is getting compiled on a higher version.代码正在更高版本上编译。 In my case, it is version 11... and就我而言,它是第 11 版......
  • the code is getting executed on a lower version.该代码正在较低版本上执行。 In my case it is version 8.就我而言,它是第 8 版。
  • Ie, Java (JDK) compiled code on 11, whereas the JRE version is 8.即,Java(JDK)在 11 上编译代码,而 JRE 版本是 8。

Where did I configure JDK 11 and JRE 8?我在哪里配置了 JDK 11 和 JRE 8?

  • I am using SpringToolSuite (STS).我正在使用 SpringToolSuite (STS)。 When I created the project, the JRE System library was in the build path, which got added as the default JRE library version of 8 (1.8).当我创建项目时,JRE System 库位于构建路径中,它被添加为默认的 JRE 库版本 8 (1.8)。 But when I go to the project → PropertiesJava CompilerCompiler Compliance Level , it is by default having a selected version of 11但是当我转到项目 →属性Java 编译器编译器合规级别时,默认情况下选择的版本为 11

Solution:解决方案:

The project → PropertiesJava CompilerCompiler Compliance Level项目 →属性Java 编译器编译器合规级别

  • Set the Compiler Compliance Level to 1.8 That's it.Compiler Compliance Level设置为 1.8 就是这样。 Now you are compiling your code in 1.8 and executing the compiled code with a JRE 1.8.现在您正在 1.8 中编译代码并使用 JRE 1.8 执行编译后的代码。

The accepted answer did not resolve the issue, hence I am posting what worked for me.接受的答案没有解决问题,因此我发布了对我有用的内容。

This is a core problem.这是一个核心问题。 Try javac --version and java --version .尝试javac --versionjava --version You will see a mismatch or inconsistency.您将看到不匹配或不一致的情况。 Try to set path variables correctly and you will not see any errors.尝试正确设置路径变量,您不会看到任何错误。

For Eclipse, right-click on the project → Properties .对于 Eclipse,右键单击项目 →属性 Then go to project facets and set the JDK to the desired version.然后转到项目方面并将 JDK 设置为所需的版本。 Then go to run-times and set JRE to the same version.然后转到运行时并将 JRE 设置为相同的版本。 You should be good.你应该很好。

I'm was trying to run my JAR file (without external JAR files) adding libraries at runtime java -cp "..." -jar myCode.jar , but when you specify -jar then the -cp parameter will be ignored .我试图运行我的 JAR 文件(没有外部 JAR 文件)在运行时添加库java -cp "..." -jar myCode.jar ,但是当您指定-jar时, -cp参数将被忽略

So you can include your JAR file in the classpath and then call your main class:所以你可以在类路径中包含你的 JAR 文件,然后调用你的主类:

java -cp "myCode.jar:/path/to/jars/*" foo.bar.MyMainClass

Run a JAR file from the command line and specify classpath 从命令行运行 JAR 文件并指定类路径

While running Java and JavaFX applications in Eclipse, I have faced the same problem.在 Eclipse 中运行 Java 和JavaFX应用程序时,我遇到了同样的问题。 But I got a simple solution.但我有一个简单的解决方案。 I have removed JDK 1.8 from the build path and added the same JDK 1.8 to the build path.我已从构建路径中删除了 JDK 1.8,并将相同的 JDK 1.8 添加到了构建路径中。 It works now.现在可以了。

I faced the same problem when I checked-out a project from a Git repository.当我从 Git 存储库签出项目时,我遇到了同样的问题。

To resolve this, I added these properties in the pom.xml file to tell which Java version to use (we are using Java 1.8, but you can use any version number as per your requirement).为了解决这个问题,我在pom.xml文件中添加了这些属性,以告知要使用哪个 Java 版本(我们使用的是 Java 1.8,但您可以根据需要使用任何版本号)。

<properties>
    <java.version>1.8</java.version>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
</properties>

This problem probably occurs because the JDK versions are inconsistent, and the JAR package will have signature files, which do not affect the logic of the program, but they will cause the test demo to fail.出现这个问题的原因可能是JDK版本不一致,JAR包会有签名文件,不影响程序逻辑,但会导致测试demo失败。 Therefore, you need to delete the signature related files in the JAR package.因此,需要删除JAR包中的签名相关文件。

Delete the .DSA and .SF files under meta-inf in the generated JAR file.删除生成的 JAR 文件中 meta-inf 下的 .DSA 和 .SF 文件。

In NetBeans 8.0.2:NetBeans 8.0.2 中:

  1. right-click on your package.右键单击您的包。
  2. Select "Properties".选择“属性”。
  3. Go to "Run" option.转到“运行”选项。
  4. Select the main class by browsing your class name.通过浏览您的班级名称来选择主要班级。
  5. Click the OK button.单击确定按钮。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:发生 JNI 错误,请检查您的安装并重试。 使用 Eclipse,TestNG - Error: A JNI error has occurred, please check your installation and try again. Using Eclipse, TestNG 错误:发生了JNI错误,请检查您的安装,然后在Eclipse EE中的Maven Project中重试 - Error: A JNI error has occurred, please check your installation and try again in Maven Project in Eclipse EE 使用 Windows 电源 shell 运行时出现错误。 发生 JNI 错误,请检查您的安装并重试 - Error occurred when running with Windows power shell. A JNI error has occurred, please check your installation and try again 错误:发生了JNI错误,请检查您的安装,然后重试。NoClassDefFound错误:DRPCExecutionException - ERROR: A JNI error has occurred, please check your installation and try again.NoClassDefFound error: DRPCExecutionException #error running igv **Error: A JNI error has occurred, please check your installation and try again - #error running igv **Error: A JNI error has occurred, please check your installation and try again 错误:发生了JNI错误,请检查您的安装,然后在IntelliJ IDEA中重试 - Error: A JNI error has occurred, please check your installation and try again in IntelliJ IDEA 错误:发生 JNI 错误,请检查您的安装并重试 - Error : A JNI error has occurred, please check your installation and try again 错误:发生JNI错误,请检查您的安装并重试:Java 17.0.5 - Error: A JNI error has occurred, please check your installation and try again: Java 17.0.5 错误:发生 JNI 错误,请检查您的安装并重试线程“main”中的异常 - Error: A JNI error has occurred, please check your installation and try again Exception in thread "main" IntelliJ IDEA - 错误:发生 JNI 错误,请检查您的安装并重试 - IntelliJ IDEA - Error: A JNI error has occurred, please check your installation and try again
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM