简体   繁体   English

“make clean all run”有效,但 Eclipse 上的项目不会运行

[英]"make clean all run" works but the project on Eclipse won't run

I'm trying to make a project, that was never used on Eclipse before, work.我正在尝试制作一个以前从未在 Eclipse 上使用过的项目。 Keep in mind that the code is not mine so I don't know everything about it.请记住,代码不是我的,所以我不知道它的一切。 The project run perfectly fine with Cygwin using "make" with the "make clean all run" command but when I'm launching it on Eclipse, I have this error message:该项目在 Cygwin 上使用“make”和“make clean all run”命令运行得非常好,但是当我在 Eclipse 上启动它时,我收到以下错误消息:

Exception in thread "main" java.lang.NullPointerException: Cannot invoke "java.awt.Image.getProperty(String, java.awt.image.ImageObserver)" because "image" is null>线程“main”中的异常 java.lang.NullPointerException:无法调用“java.awt.Image.getProperty(String, java.awt.image.ImageObserver)”,因为“image”为 null>

That error is caused by (the last line in the first code section):该错误是由(第一个代码部分的最后一行)引起的:

private void initClass() {

    BufferedImage prefs_image;

    prefs_image     = MBMImagesDico.loadBestImage(ICON_PREFS_STR,
                                              Transparency.TRANSLUCENT);
    _prefs_icon     = new ImageIcon(prefs_image);
}

and (the last line in this code section):和(此代码部分的最后一行):

public ImageIcon (Image image) {
    this.image = image;
    Object o = image.getProperty("comment", imageObserver);
}

because image is null.因为图像是 null。

It seems that Eclipse is not finding the image file that the program is looking for.似乎 Eclipse 没有找到程序正在寻找的图像文件。 So I tried:所以我尝试了:

  • Changing the BuildPath to include the ressource folder (here it's called Images) or the Icons folder included in the Images folder.更改 BuildPath 以包含资源文件夹(此处称为 Images)或 Images 文件夹中包含的 Icons 文件夹。 Neither or that worked两者都不起作用
  • Changing the working directory from default to the bin of the project Here is a picture of what "changing the working directory" means将工作目录从默认更改为项目的 bin这是“更改工作目录”的含义的图片
  • Cheching that the bin do include the images files, the ressource folder and that the asked path is coresponding to what is built in the bin检查 bin 是否包含图像文件、资源文件夹以及询问的路径是否与 bin 中构建的内容相对应
  • Looking intensively at the code to understand why I am getting a null (while knowing everything works fine when using "make so that was hopeless)仔细查看代码以了解为什么我得到 null(同时知道使用“make so that was hopeless 时一切正常”)

And I still didn't find a solution.而且我仍然没有找到解决方案。

I'm using Eclipe 2021-09 (4.21.0) and java 8u202.我正在使用 Eclipe 2021-09 (4.21.0) 和 java 8u202。

I'm including a picture of the path in debug mode and the actual path in the bin.我包括一张调试模式下的路径图片和 bin 中的实际路径。 As you can see, it "should" work.如您所见,它“应该”起作用。 The path demanded during the execution The path in the bin folder in the project folder执行过程中需要的路径 项目文件夹中bin文件夹中的路径

It's my first post on StackOverflow so I'm sorry in advance if I didn't include enough informations or I talked too much.这是我在 StackOverflow 上的第一篇文章,所以如果我没有包含足够的信息或我说得太多,我提前道歉。 I'm a bit desperate (it's probably easy to fix).我有点绝望(它可能很容易修复)。 Wish you all a good day.祝大家有个美好的一天。

Turns out the problem was that I was using the wrong version of the JRE and had nothing to do with the build path or the source directory.原来问题是我使用了错误版本的 JRE,并且与构建路径或源目录无关。

So this how I fixed it:所以这就是我修复它的方式:

  • I cancelled everything that I tried first, for example I set back the working directory to default.我取消了我首先尝试的所有内容,例如我将工作目录设置回默认值。
  • I went to "run configuration" in the "JRE" tab and selected "Alternate JRE".我转到“JRE”选项卡中的“运行配置”并选择“备用 JRE”。 I added the propper JRE with the "Installed JRE" and "Add" button (in my case I had to add an 1.8 jdk file).我使用“已安装的 JRE”和“添加”按钮添加了适当的 JRE(在我的例子中,我必须添加一个 1.8 jdk 文件)。
  • Don't forget to select the jre you just added in the dropdown menu (yes I forgot at first).不要忘记 select 您刚刚在下拉菜单中添加的 jre(是的,我一开始忘记了)。
  • Then I hit "Apply" and "Run" and everything worked, finally.然后我点击“应用”和“运行”,最后一切正常。

Here is a picture of the "JRE" tab in "Run configuration"这是“运行配置”中“JRE”选项卡的图片

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

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