jave项目出错 [英] Error in jave project

查看:84
本文介绍了jave项目出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我输入了一个教程中的代码现在它在2个类中给出了错误,并且idont知道如何修复它我会在这里给出我的脚本和错误:



错误:

------------------------

so i typed a code from a tutorial now it gives errors in 2 classes and idont know how to fix it il will give my scripts and my error here:

error:
------------------------

Exception in thread "Thread-2" java.lang.IllegalArgumentException: input == null!
	at javax.imageio.ImageIO.read(Unknown Source)
	at game.BufferedImageLoader.loadImage(BufferedImageLoader.java:14)
	at game.Game.init(Game.java:28)
	at game.Game.run(Game.java:63)
	at java.lang.Thread.run(Unknown Source)



---------- --------------



代码中有错误的部分。





初始化函数。

--------------------------- ---


------------------------

the parts of code with error.


the init function.
------------------------------

public void init(){
		BufferedImageLoader loader = new BufferedImageLoader();
		try{
			
			spriteSheet = loader.loadImage("download.png");
			
		}catch(IOException e){
			e.printStackTrace();
		}
	}



------------------------- -----



BufferedImageLoader类



---------- --------------------


------------------------------

the BufferedImageLoader class

------------------------------

package game;

import java.awt.image.BufferedImage;
import java.io.IOException;

import javax.imageio.ImageIO;

public class BufferedImageLoader {

	private BufferedImage image;
	
	public BufferedImage loadImage(String path) throws IOException{
		
		image = ImageIO.read(getClass().getResource(path));
		return image;
		
		
		
	}
	
}



--------- -------------------



我的尝试:



i试图改变路径文件,但它不起作用


----------------------------

What I have tried:

i have tried to change the path files but it did not work

推荐答案

制作一个资源项目目录中的文件夹。它应该可以正常工作。

getResource()函数从项目目录中的资源文件夹中获取文件。
Make a "resources" folder in project directory. It should work correctly.
getResource() function get file from resources folder from project directory.


这篇关于jave项目出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆