所以我对java有点新鲜,我和我的一个朋友一起创建了一个简单的游戏。我已经达到了想要发布它的jar文件以便人们可以播放的程度。我在Eclipse中导出了一个项目罐,没有任何问题。但是当我运行它时,它只是创建了JFrame,而不是游戏。我可以在eclipse中运行它,没有任何问题,但在它之外它不起作用。我创建了一个.bat文件来启动jar并在控制台上发现错误:
Exception in thread "Thread-2" java.lang.IllegalArgumentException: input == null!
at javax.imageio.ImageIO.read<ImageIO.java:1388>
at images.ImageLoader.load<ImageLoader.java:10>
at main.base.init<base.java:37>
at main.base.run<base.java:73>
at java.lang.Thread.run<Thread.java:745>
我确实检查了清单,并且它具有正确的主类集。所以我在这里没有想法...... 这是我的主文件的代码:
package main;
import images.ImageLoader;
import images.ImageManager;
import images.SpriteSheet;
import java.awt.Canvas;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.image.BufferStrategy;
import java.awt.image.BufferedImage;
import javax.swing.JFrame;
public class base extends Canvas implements Runnable{
//CREDIT: Thanks to CodeNMore for some base code for the game
private static final long serialVersionUID = 1L;
public static final int WIDTH = 484, HEIGHT = 365, SCALE = 2, TILESIZE = 24; //484, 365, scale=2
public static boolean running = false;
public Thread gameThread;
private BufferedImage spriteSheet;
private static BufferedImage cl;
public static BufferedImage console;
private static ImageManager im;
private static Player player;
private static Level level;
private String Level[] = {"/level1.png","/level2.png","/level3.png"};
public static String currentLevel;
private static HUDLoader hud;
public void init(){
ImageLoader loader = new ImageLoader();
spriteSheet = loader.load("/spritesheet.png");
SpriteSheet ss = new SpriteSheet(spriteSheet);
im = new ImageManager(ss);
player = new Player(im);
console = loader.load("/console.png");
hud = new HUDLoader(console);
this.addKeyListener(new KeyManager());
setLevel(Level[2]);
cl = loader.load(currentLevel);
level = new Level(cl);
}
public static BufferedImage getLevel(){
return cl;
}
public void setLevel(String set){
currentLevel = set;
}
public synchronized void start(){
if(running)return;
running = true;
gameThread = new Thread(this);
gameThread.start();
}
public synchronized void stop(){
if(!running)return;
running = false;
try {
gameThread.join();
} catch (InterruptedException e) {e.printStackTrace();}
}
public void run(){
init();
long lastTime = System.nanoTime();
final double amountOfTicks = 60D;
double ns = 1000000000 / amountOfTicks;
double delta = 0;
while(running){
long now = System.nanoTime();
delta += (now - lastTime) / ns;
lastTime = now;
if(delta >= 1){
tick();
delta--;
}
render();
}
stop();
}
public void tick(){
player.tick();
hud.tick();
}
public void render(){
BufferStrategy bs = this.getBufferStrategy();
if(bs == null){
createBufferStrategy(3);
return;
}
Graphics g = bs.getDrawGraphics();
//RENDER
g.fillRect(0, 0, WIDTH * SCALE, HEIGHT * SCALE);
level.render(g);
player.render(g);
hud.render(g);
//Reset Render
g.dispose();
bs.show();
}
public static void main(String[] args){
base game = new base();
game.setPreferredSize(new Dimension(WIDTH * SCALE, HEIGHT * SCALE));
game.setMaximumSize(new Dimension(WIDTH * SCALE, HEIGHT * SCALE));
game.setMinimumSize(new Dimension(WIDTH * SCALE, HEIGHT * SCALE));
JFrame frame = new JFrame("The Legend of Taco");
frame.setSize(WIDTH * SCALE, HEIGHT * SCALE);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setResizable(false);
frame.add(game);
frame.setVisible(true);
game.start();
}
public static Player getPlayer(){
return player;
}
public static HUDLoader getHud(){
return hud;
}
public static ImageManager getImageManager(){
return im;
}
}
任何帮助表示赞赏! 〜汤姆
答案 0 :(得分:0)
我认为你在eclipse中使用的是不同的Java版本。您可以添加在外部使用的JDK或JRE。
选择“窗口”菜单 - >“首选项”。然后选择Java-&gt; Installed JRE。然后单击“添加”。