java - 修复输入 == null!创建图像时出错
问题描述
我正在尝试加载精灵表,但它不起作用。它在线程“Thread-0”java.lang.IllegalArgumentException 中给出错误异常:输入 == null!
我将图像保存到文件夹 } res --> Textures --> sheet.png 。我通过构建路径确保 res 文件夹位于 Class 文件夹中。
请帮忙
// public class Game
private void init(){
display = new Display(title, width, height);
test = BufferedImageLoader.loadImage("/sheets.png");
Assets.init();
}
private void render(){
bs = display.getCanvas().getBufferStrategy();
if(bs == null){
display.getCanvas().createBufferStrategy(3);
return;
}
g = bs.getDrawGraphics();
g.clearRect(0, 0, width, height);
g.drawImage(test, x, 10, null);
//End Drawing!
bs.show();
g.dispose();
}
// 公共类 BufferedImageLoader {
public static BufferedImage loadImage(String path){
try {
return ImageIO.read(BufferedImageLoader.class.getClassLoader().getResourceAsStream(path));
} catch (IOException e) {
e.printStackTrace();
System.exit(1);
}
return null;
}
}
解决方案
弄清楚了!使用源文件夹中的所有图像创建一个单独的文件夹。然后,使用链接 /folder name/ photo name 。格式(例如“/Images/mario.png”)。这种方式有效。
推荐阅读
- php - 重写查询字符串以允许 wordpress 中单个自定义帖子类型的多个 URL
- c++ - 带有 std::quoted 的 Visual Studio 中的错误
- r - RandomForest没有计算OOB错误
- ruby-on-rails - 2 分钟 Rails/AngularJS 后 SSO/SAML 会话超时
- html - 填充整页 div,每边减去填充
- javascript - 为什么javascript不能逐行运行
- react-native - 如何在加载数据时同时渲染 FlatList 的 listItem?
- ruby-on-rails - 多对多 ElasticSearch - Rails
- r - 通过其他两列创建排序的排名 ID
- sql - 从 MySQL 查询中计算不同的 0 值