我一直在研究LIBGDX游戏一段时间,上周我更新了Android Studio到版本2.1.2。更新后,我开始获取java.lang.ExceptionInInitializerError
,当屏幕类中的渲染方法试图绘制从另一个类中调用的静态图像时。 “ batcher.begin(); batcher.draw(Assets.rockWall,0,0,160,90); ”Android Studio java.lang.ExceptionInInitializerError静态游戏资产被调用绘制时
这是我的错误日志:
07-24 12:12:10.702 9442-9489/? E/AndroidRuntime: FATAL EXCEPTION: GLThread 32587 Process: com.dotabmot.game, PID: 9442 java.lang.ExceptionInInitializerError at com.dotabmot.game.StartMenuScreen.render(StartMenuScreen.java:108) at com.badlogic.gdx.Game.render(Game.java:46) at com.badlogic.gdx.backends.android.AndroidGraphics.onDrawFrame(AndroidGraphics.java:474) at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1531) at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1248) Caused by: com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load file: trollWalk1.png at com.badlogic.gdx.graphics.Pixmap.(Pixmap.java:148) at com.badlogic.gdx.graphics.TextureData$Factory.loadFromFile(TextureData.java:98) at com.badlogic.gdx.graphics.Texture.(Texture.java:100) at com.badlogic.gdx.graphics.Texture.(Texture.java:92) at com.dotabmot.game.Assets.(Assets.java:112) at com.dotabmot.game.StartMenuScreen.render(StartMenuScreen.java:108) at com.badlogic.gdx.Game.render(Game.java:46) at com.badlogic.gdx.backends.android.AndroidGraphics.onDrawFrame(AndroidGraphics.java:474) at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1531) at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1248) Caused by: com.badlogic.gdx.utils.GdxRuntimeException: Error reading file: trollWalk1.png (Internal) at com.badlogic.gdx.backends.android.AndroidFileHandle.read(AndroidFileHandle.java:77) at com.badlogic.gdx.files.FileHandle.readBytes(FileHandle.java:222) at com.badlogic.gdx.graphics.Pixmap.(Pixmap.java:145) at com.badlogic.gdx.graphics.TextureData$Factory.loadFromFile(TextureData.java:98) at com.badlogic.gdx.graphics.Texture.(Texture.java:100) at com.badlogic.gdx.graphics.Texture.(Texture.java:92) at com.dotabmot.game.Assets.(Assets.java:112) at com.dotabmot.game.StartMenuScreen.render(StartMenuScreen.java:108) at com.badlogic.gdx.Game.render(Game.java:46) at com.badlogic.gdx.backends.android.AndroidGraphics.onDrawFrame(AndroidGraphics.java:474) at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1531) at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1248) Caused by: java.io.FileNotFoundException: trollWalk1.png at android.content.res.AssetManager.openAsset(Native Method) at android.content.res.AssetManager.open(AssetManager.java:324) at android.content.res.AssetManager.open(AssetManager.java:298) at com.badlogic.gdx.backends.android.AndroidFileHandle.read(AndroidFileHandle.java:75) at com.badlogic.gdx.files.FileHandle.readBytes(FileHandle.java:222) at com.badlogic.gdx.graphics.Pixmap.(Pixmap.java:145) at com.badlogic.gdx.graphics.TextureData$Factory.loadFromFile(TextureData.java:98) at com.badlogic.gdx.graphics.Texture.(Texture.java:100) at com.badlogic.gdx.graphics.Texture.(Texture.java:92) at com.dotabmot.game.Assets.(Assets.java:112) at com.dotabmot.game.StartMenuScreen.render(StartMenuScreen.java:108) at com.badlogic.gdx.Game.render(Game.java:46) at com.badlogic.gdx.backends.android.AndroidGraphics.onDrawFrame(AndroidGraphics.java:474) at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1531) at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1248) 07-24 12:12:14.782 9442-9442/? E/AndroidGraphics: waiting for pause synchronization took too long; assuming deadlock and killing
Android Studio中没有显示出编译时出错,如何解决这个错误?
下面是一些代码,是关系到错误: 内部资产类别:
公共类资产{
// The Rock Wall Background
public static Texture textureRockWall = new Texture(Gdx.files.internal("rockWall.jpg"));
public static TextureRegion rockWall = new TextureRegion(textureRockWall, 0, 0, 600, 450);
// The New Game Button
public static Texture textureNewGameButton = new Texture(Gdx.files.internal("newGameButton.png"));
public static TextureRegion newGameButton = new TextureRegion(textureNewGameButton, 0, 0, 139, 351);
里面的StartMenuScreen类:
公共类StartMenuScreen实施屏幕{
public void render(float delta){
这里// Draw Background Rock Wall
batcher.begin();
batcher.draw(Assets.rockWall, 0, 0, 160, 90); **// THIS LINE IS WHERE I GET THE ERROR. IF I REMOVE THIS LINE I GET THE SAME ERROR FOR THE NEXT STATIC OBJECT WHICH IS Assets.newGameButtonClicked...**
//Screen1
if(screen1) {
if(!StartMenuScreenInputHandler.newGameButtonClicked) {
batcher.draw(Assets.newGameButton, 50, 15, 15, 60);
} else if(StartMenuScreenInputHandler.newGameButtonClicked){
batcher.draw(Assets.newGameButtonP, 50, 15, 15, 60);
if(goAhead){
goAhead = false;
StartMenuScreenInputHandler.newGameButtonClicked = false;
buttonCounter = 0;
screen1 = false;
screen2 = true;
}
}
}
所以很难说没有看到任何代码... – nasch
的Nasch你好,我添加了相关的代码,因为它将投入更多时间太长。你能再看一遍吗?非常感谢。 – Oguzhan
“StartMenuScreen”第108行在哪里? – nasch