简体   繁体   English

在 eclipse 中构建我的 java 应用程序后出错

[英]Error after building my java app in eclipse

I'm learning java and tried to build a very simple app that i created in Eclipse .我正在学习java并尝试构建我在Eclipse中创建的非常简单的app

The app basically just asks the user if he could see clouds at the sky.app基本上只是询问用户是否可以看到天空中的云。 If he says yes, then the app says "oh its cloudy", if he says no, the app says "its sunshine" (all that only in german).如果他说是,那么应用程序会说“哦,它多云”,如果他说不,应用程序会说“它的阳光”(所有这些都只有德语)。

This is the full code of the app这是app的完整代码

import javax.swing.JOptionPane;

public class Wetteransage {

    public static void main(String[] args) {
        
        int wetterInfo = JOptionPane.showConfirmDialog(null, "Siehst du Wolken am Himmel?");
        
        switch (wetterInfo)
        {
        case 0:
            JOptionPane.showMessageDialog(null, "Dann ist es wohl bewölkt...");
            break;
        case 1:
            JOptionPane.showMessageDialog(null, "Oh wie schön, die Sonne scheint!");
            break;
        case 2:
            JOptionPane.showMessageDialog(null, "Du bist dir wohl nicht sicher, was?");
            break;
        }

    }

}

When i run it inside eclipse, everything works fine.当我在 eclipse 中运行它时,一切正常。

But when i export it and try to run the .jar file, it gives me a Error:但是当我导出它并尝试运行.jar文件时,它给了我一个错误:

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

A Java Exception as occurred.发生了 Java 异常。

One potential issue that could cause this error in Eclipse is the existing of an old version of the app in your "Run Configurations" list.在 Eclipse 中可能导致此错误的一个潜在问题是“运行配置”列表中存在旧版本的app To get around this problem, you could EXPLICITLY right-click the file you want to run and then select "Run As Java Application."要解决此问题,您可以明确右键单击要运行的文件,然后 select "Run As Java Application"。

A better way to do this is to open your "Run Configurations" and delete old versions of it.一个更好的方法是打开你的“运行配置”并删除它的旧版本。 To open your "run configurations", simply click on the black down-arrow next to your "Run" green icon and select "Run Configurations"要打开“运行配置”,只需单击“运行”绿色图标和 select“运行配置”旁边的黑色向下箭头

在此处输入图像描述

Once you open the Run Configurations window, go to the listed Java applications and delete the ones you don't need.打开运行配置 window、go 到列出的 Java 应用程序并删除不需要的应用程序后。

在此处输入图像描述

Lastly, select the Java application you want to run, and just run it.最后,select 你想运行的 Java 应用程序,然后运行它。 The problem, if related to this specific condition, should be gone.这个问题,如果与这个特定的条件有关,应该已经消失了。

UPDATE : I didn't quite see the OP last statement about the error being when executing the JAR.更新:在执行 JAR 时,我没有完全看到关于错误的 OP 最后声明。 A JNI error while executing the JAR could be caused by one or more of the issues listed below:执行 JAR 时出现 JNI 错误可能是由下列一个或多个问题引起的:

  1. Dependencies on 3rd-party JNI libraries (don't appear to be the case here)对 3rd-party JNI 库的依赖(这里似乎不是这种情况)
  2. Corrupted Java installation (I have never seen this before, but could happen)损坏的 Java 安装(我以前从未见过这种情况,但可能会发生)
  3. "Incompatible" JREs - I have experienced all kinds of issues with having multiple versions of Java Runtime Environments in Windows machine. “不兼容”的 JRE - 我在 Windows 机器中遇到了多个版本的 Java 运行时环境的各种问题。 To avoid these issues, make sure you are using the right JRE.为避免这些问题,请确保您使用的是正确的 JRE。 While I am not 100% this will result in a JNI error, I don't rule this out.虽然我不是 100% 这会导致 JNI 错误,但我不排除这种可能性。 One way to find out is to invoke the java command from the same Java home folder you use to compile the code.找出答案的一种方法是从用于编译代码的同一 Java 主文件夹调用java命令。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM