为什么某些 Java 类 可以访问我的 IntelliJ IDEA 项目中的图像,但 JavaFX 中的其他图像不能访问?

Why are images in my IntelliJ IDEA project accessible to some Java classes but aren't to others in JavaFX?

我正在 JavaFX 中开发一个简单的 2D 游戏,我将我的一些资产(只是一堆文件夹和图像)加载到我的项目到它们自己的目录中,然后去制作另一个 Java class 用于播放器需要的所有内容(移动、按键、加载播放器资产),并且 none 正在加载图像。有谁知道为什么?我知道导致以下问题的代码。

class Player
{
    public Player() throws FileNotFoundException 
    {
        System.exit(-1);
    }

    Image leftSide = new Image(new FileInputStream("resources/player/leftNO.png");
    ImageView leftSideView = new ImageView(leftSide);
}

我的目录如下:

有人知道为什么会这样吗?提前致谢,即使您没有答案。

编辑:此外,我忘了提及当我尝试在 Main.java class 中打开图像时,它加载正常。

你说不加载,是说抛出异常还是空白? 这取决于哪个,这可能有效:

将您的资源目录标记为源文件夹并尝试

class Player
{
    public Player() throws FileNotFoundException 
    {
        System.exit(-1);
    }

    Image leftSide = new Image(getClass().getResourceAsStream("/player/leftNO.png");
    ImageView leftSideView = new ImageView(leftSide);
}

这还将允许您的应用程序在 jar 中工作