我得到了
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f060000
当我尝试从res / drawable文件夹中的资源加载位图时(甚至是IntelliJ auto-complete找到它们),如下所示:
public Sprite(int resource, int numberOfFrames){
BitmapRegionDecoder spriteSheet = null;
try {
InputStream is = Resources.getSystem().openRawResource(+resource);
spriteSheet = BitmapRegionDecoder.newInstance(is, false);
} catch (IOException ioexc){
ioexc.printStackTrace();
}
timer = 0;
this.numberOfFrames = numberOfFrames;
frames = new Bitmap[numberOfFrames];
for (int i = 0; i < numberOfFrames; i++) {
frames[i] = spriteSheet.decodeRegion(new Rect(i*32, 0, (i*32)+32, 32), null);
}
我只传了两次资源:
public class PlayerSprite extends Sprite {
private boolean isHitting;
private int timer;
public PlayerSprite() {
super(R.drawable.player_sprite_sheet, 3);
timer = 0;
}
//...more core...//
}
在这里:
sprite = new Sprite(R.drawable.ball_sprite, 7);
在这里,您可以看到我的directory
答案 0 :(得分:0)
Resources.getSystem()
是您的问题所在。它返回一个全局共享的Resources对象,但不返回该应用程序的对象。您应该使用Context.getResource()
代替
的文档应用程序包的资源实例