我正在用JavaFX开发一个简单的2D游戏,我将我的一些资产(只是一堆文件夹和图像)加载到我的项目中的自己的目录中,并为所有内容创建了另一个Java类。玩家需求(移动,按键,加载玩家资产),并且没有图像加载。有人知道为什么吗?我知道以下导致问题的代码。
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 Player
{
public Player() throws FileNotFoundException
{
System.exit(-1);
}
Image leftSide = new Image(getClass().getResourceAsStream("/player/leftNO.png");
ImageView leftSideView = new ImageView(leftSide);
}
这也将使您的应用程序可以在罐中工作