在Eclipse 2D中点击Run时出错

时间:2013-02-24 17:39:44

标签: java eclipse slick2d

我是使用Eclipse和java在Slick 2D中学习基本游戏编程的菜鸟 我正在关注https://www.youtube.com/watch?annotation_id=annotation_871076&feature=iv&src_vid=NoksHLldlcM&v=oWm5JY6IlUo的教程,当我点击运行时它不起作用。我收到此错误

Exception in thread "main" java.lang.RuntimeException: Resource not found:     testdata/alphamap.png
at org.newdawn.slick.util.ResourceLoader.getResourceAsStream(ResourceLoader.java:69)
at org.newdawn.slick.opengl.InternalTextureLoader.getTexture(InternalTextureLoader.java:169)
at org.newdawn.slick.Image.<init>(Image.java:196)
at org.newdawn.slick.Image.<init>(Image.java:170)
at org.newdawn.slick.Image.<init>(Image.java:158)
at org.newdawn.slick.Image.<init>(Image.java:136)
at org.newdawn.slick.tests.AlphaMapTest.init(AlphaMapTest.java:33)
at org.newdawn.slick.AppGameContainer.setup(AppGameContainer.java:390)
at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:314)
at org.newdawn.slick.tests.AlphaMapTest.main(AlphaMapTest.java:79)

这就是我的尝试

import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.BasicGame;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;


public class Main extends BasicGame{

private static final String Slick2D = null;

public Main(String title) {
    super(title);
    // TODO Auto-generated constructor stub
}

//this is where execution starts
public static void man(String args[]) throws SlickException {

    AppGameContainer app = new AppGameContainer(new Main("First Slick2D"));
    app.setDisplayMode(800, 600, false);
    app.start();

}

@Override
public void render(GameContainer gc, Graphics g) throws SlickException {
    // draw all the graphics
    g.fillOval(200, 200, 100, 300)
    g.fillRect(300, 200, 100, 200)
    g.fillRoundRect(500, 200, 100, 50, 30)
    g.drawLine(0, 0, 800, 600)
    g.drawString(Welcome to Slick2D, 400, 0)
}

@Override
public void init(GameContainer arg0) throws SlickException {
    // load all fonts, graphics, sounds, etc.

}

@Override
public void update(GameContainer arg0, int arg1) throws SlickException {
    // game logic (AI, user input)

}

}

2 个答案:

答案 0 :(得分:0)

它根本无法找到图像。检查你的scr文件夹中的testdata文件夹并检查它是否包含alphamap.png(或者你可以删除一些你得到的代码并设置这张图片)

答案 1 :(得分:0)

Slick希望图像位于名为images的文件夹中。我不确定为什么,但确实如此。

你的指示应该是这样的:

\ SRC \ Main.java

\图像\ alphamap.png

如果这不起作用,请确保您的目录已正确命名且位于项目文件夹中,而不是src文件夹中。

示例:

\ MyProject \ src \ Main.java是您的源代码

\ MyProject的\图像\ alphamap.png