我正在制作游戏,我需要将大量图像加载到自定义精灵中。前59个工作,但随机停止在武器5工作。
这是我得到的错误:
Exception in thread "main" java.lang.ExceptionInInitializerError
at rendering.Pinpoint.<init>(Pinpoint.java:27)
at start.SCCMAIN$RenderThread.<init>(SCCMAIN.java:67)
at start.SCCMAIN.<init>(SCCMAIN.java:34)
at start.SCCMAIN.main(SCCMAIN.java:210)
Caused by: java.lang.IllegalArgumentException: input == null!
at javax.imageio.ImageIO.read(Unknown Source)
at rendering.Sprite.<init>(Sprite.java:151)
at rendering.Sprite.<clinit>(Sprite.java:76)
... 4 more
以下是我创建sprite的代码:
...public static final Sprite Core1=new Sprite(22,22,"/assets/main/images/parts/Core_1.PNG");
public static final Sprite Core2=new Sprite("/assets/main/images/parts/Core_2.PNG");
public static final Sprite Core3=new Sprite("/assets/main/images/parts/Core_3.PNG");
public static final Sprite Core4=new Sprite("/assets/main/images/parts/Core_4.PNG");
public static final Sprite Center1=new Sprite("/assets/main/images/parts/Center_1.PNG");
public static final Sprite Ability1=new Sprite("/assets/main/images/weapons/weapon_1.PNG");
public static final Sprite Ability2=new Sprite("/assets/main/images/weapons/weapon_2.PNG");
public static final Sprite Ability3=new Sprite("/assets/main/images/weapons/weapon_3.PNG");
public static final Sprite Ability4=new Sprite("/assets/main/images/weapons/weapon_4.PNG");
public static final Sprite Ability5=new Sprite("/assets/main/images/weapons/weapon_5.PGN");
public static final Sprite Ability6=new Sprite("/assets/main/images/weapons/weapon_6.PGN");...
这是Sprite构造函数:
public Sprite(String s)
{
try {
this.image=ImageIO.read(getClass().getResourceAsStream(s));
} catch (IOException e) {
e.printStackTrace();
}
this.doubledOffSetX=this.image.getWidth();
this.doubledOffSetY=this.image.getHeight();
this.id=currentId;
Sprite.currentId++;
System.out.println(Sprite.getCurrentId());
}
编辑:原来我将武器5+命名为PGN文件而不是PNG文件。
答案 0 :(得分:1)
什么是PGN文件? .pgn文件扩展名最常与Picatinny Arsenal Electronic Formstore图像文件相关联。 PGN文件是Picatinny Arsenal Electronic Formstore使用的TIFF文件格式。 PGN文件是以无损压缩格式存储的压缩图像文件。
PGN文件确实是图像,但似乎ImageIO不支持这种格式,请查看规范http://docs.oracle.com/javase/7/docs/api/javax/imageio/package-summary.html