Java Android Studio应用程序甚至在使用Libgdx打开之前就停止工作了
我在Android Studio上构建了一个简单的应用程序,使用Libgdx来显示由6.png图像组成的动画,我制作了一个TextureAtlas。该项目构建良好,没有任何错误,但当我尝试在模拟器中运行应用程序时,它在打开时崩溃。我知道这不是emulator的错误,因为我已经成功地使用相同的配置和库构建了一个应用程序来显示文本,并且这个应用程序在我的Galaxy Note 5上也崩溃了 下面是core.java文件的代码:Java Android Studio应用程序甚至在使用Libgdx打开之前就停止工作了,java,android,android-studio,libgdx,texture-atlas,Java,Android,Android Studio,Libgdx,Texture Atlas,我在Android Studio上构建了一个简单的应用程序,使用Libgdx来显示由6.png图像组成的动画,我制作了一个TextureAtlas。该项目构建良好,没有任何错误,但当我尝试在模拟器中运行应用程序时,它在打开时崩溃。我知道这不是emulator的错误,因为我已经成功地使用相同的配置和库构建了一个应用程序来显示文本,并且这个应用程序在我的Galaxy Note 5上也崩溃了 下面是core.java文件的代码: package com.mygdx.mytestgame; impor
package com.mygdx.mytestgame;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.Animation;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
public class MyTestGame extends ApplicationAdapter {
private SpriteBatch batch;
private TextureAtlas shooterAtlas;
private Animation<TextureRegion> animation;
private float timePassed = 0;
@Override
public void create () {
batch = new SpriteBatch();
shooterAtlas = new TextureAtlas(Gdx.files.internal("shooter.atlas"));
animation = new Animation<TextureRegion>(1/30f, shooterAtlas.getRegions());
}
@Override
public void dispose() {
batch.dispose();
shooterAtlas.dispose();
}
@Override
public void render () {
Gdx.gl.glClearColor(0,1,0,1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
timePassed += Gdx.graphics.getDeltaTime();
batch.draw(animation.getKeyFrame(timePassed, true), 300, 500);
batch.end();
}
}
package com.mygdx.mytestgame;
导入com.badlogic.gdx.ApplicationAdapter;
导入com.badlogic.gdx.gdx;
导入com.badlogic.gdx.graphics.GL20;
导入com.badlogic.gdx.graphics.g2d.SpriteBatch;
导入com.badlogic.gdx.graphics.g2d.Animation;
导入com.badlogic.gdx.graphics.g2d.TextureAtlas;
导入com.badlogic.gdx.graphics.g2d.TextureRegion;
公共类MyTestGame扩展了ApplicationAdapter{
专用SpriteBatch批次;
私人酒店;
私人动画;
私有float timePassed=0;
@凌驾
公共void创建(){
批次=新的SpriteBatch();
shooterAtlas=新的TextureAtlas(Gdx.files.internal(“shooter.atlas”);
动画=新动画(1/30f,shooterAtlas.getRegions());
}
@凌驾
公共空间处置(){
batch.dispose();
shooterAtlas.dispose();
}
@凌驾
公共无效渲染(){
Gdx.gl.glClearColor(0,1,0,1);
Gdx.gl.glClear(GL20.gl\u颜色\u缓冲\u位);
batch.begin();
timePassed+=Gdx.graphics.getDeltaTime();
batch.draw(animation.getKeyFrame(timePassed,true),300500);
batch.end();
}
}
以下是Android清单文件:
<?xml version="1.0" encoding="utf-8"?>
以下是logcat上显示的碰撞:
11-02 12:52:27.514 3634-3666/com.mygdx.mytestgame E/AndroidRuntime: FATAL EXCEPTION: GLThread 193
Process: com.mygdx.mytestgame, PID: 3634
com.badlogic.gdx.utils.GdxRuntimeException: Error reading file: shooter.atlas (Internal)
at com.badlogic.gdx.backends.android.AndroidFileHandle.read(AndroidFileHandle.java:77)
at com.badlogic.gdx.graphics.g2d.TextureAtlas$TextureAtlasData.<init>(TextureAtlas.java:103)
at com.badlogic.gdx.graphics.g2d.TextureAtlas.<init>(TextureAtlas.java:231)
at com.badlogic.gdx.graphics.g2d.TextureAtlas.<init>(TextureAtlas.java:226)
at com.badlogic.gdx.graphics.g2d.TextureAtlas.<init>(TextureAtlas.java:216)
at com.mygdx.mytestgame.MyTestGame.create(MyTestGame.java:21)
at com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:275)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1555)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1270)
Caused by: java.io.FileNotFoundException: shooter.atlas
at android.content.res.AssetManager.openAsset(Native Method)
at android.content.res.AssetManager.open(AssetManager.java:374)
at android.content.res.AssetManager.open(AssetManager.java:348)
at com.badlogic.gdx.backends.android.AndroidFileHandle.read(AndroidFileHandle.java:75)
at com.badlogic.gdx.graphics.g2d.TextureAtlas$TextureAtlasData.<init>(TextureAtlas.java:103)
at com.badlogic.gdx.graphics.g2d.TextureAtlas.<init>(TextureAtlas.java:231)
at com.badlogic.gdx.graphics.g2d.TextureAtlas.<init>(TextureAtlas.java:226)
at com.badlogic.gdx.graphics.g2d.TextureAtlas.<init>(TextureAtlas.java:216)
at com.mygdx.mytestgame.MyTestGame.create(MyTestGame.java:21)
at com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:275)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1555)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1270)
11-02 12:52:27.514 3634-3666/com.mygdx.mytestgame E/AndroidRuntime:致命异常:glthread193
进程:com.mygdx.mytestgame,PID:3634
com.badlogic.gdx.utils.GdxRuntimeException:读取文件时出错:shooter.atlas(内部)
位于com.badlogic.gdx.backends.android.AndroidFileHandle.read(AndroidFileHandle.java:77)
位于com.badlogic.gdx.graphics.g2d.TextureAtlas$TextureAtlasData。(TextureAtlas.java:103)
位于com.badlogic.gdx.graphics.g2d.TextureAtlas。(TextureAtlas.java:231)
位于com.badlogic.gdx.graphics.g2d.TextureAtlas。(TextureAtlas.java:226)
位于com.badlogic.gdx.graphics.g2d.TextureAtlas。(TextureAtlas.java:216)
在com.mygdx.mytestgame.mytestgame.create上(mytestgame.java:21)
位于com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:275)
位于android.opengl.GLSurfaceView$GLThread.guarderun(GLSurfaceView.java:1555)
位于android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1270)
原因:java.io.FileNotFoundException:shooter.atlas
位于android.content.res.AssetManager.openAsset(本机方法)
位于android.content.res.AssetManager.open(AssetManager.java:374)
位于android.content.res.AssetManager.open(AssetManager.java:348)
位于com.badlogic.gdx.backends.android.AndroidFileHandle.read(AndroidFileHandle.java:75)
位于com.badlogic.gdx.graphics.g2d.TextureAtlas$TextureAtlasData。(TextureAtlas.java:103)
位于com.badlogic.gdx.graphics.g2d.TextureAtlas。(TextureAtlas.java:231)
位于com.badlogic.gdx.graphics.g2d.TextureAtlas。(TextureAtlas.java:226)
位于com.badlogic.gdx.graphics.g2d.TextureAtlas。(TextureAtlas.java:216)
在com.mygdx.mytestgame.mytestgame.create上(mytestgame.java:21)
位于com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:275)
位于android.opengl.GLSurfaceView$GLThread.guarderun(GLSurfaceView.java:1555)
位于android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1270)
它说读取文件“shooter.atlas”时出错,该文件是我用于动画的TextureAtlas。此文件名正确,位于C:\Users\user\Documents\libGDX Projects\android\assets
解决这个问题的办法是什么?我解决了这个问题,事实证明,这个问题很琐碎。我从网上下载了atlas文件,该文件的格式不正确。相反,它是一个包含.png文件的文件夹。因此,我提取了这些.png文件,并使用gdx-texturepacker.jar工具(可以是downloa)从.png文件中手动打包了一个Atlas文件
11-02 12:52:27.514 3634-3666/com.mygdx.mytestgame E/AndroidRuntime: FATAL EXCEPTION: GLThread 193
Process: com.mygdx.mytestgame, PID: 3634
com.badlogic.gdx.utils.GdxRuntimeException: Error reading file: shooter.atlas (Internal)
at com.badlogic.gdx.backends.android.AndroidFileHandle.read(AndroidFileHandle.java:77)
at com.badlogic.gdx.graphics.g2d.TextureAtlas$TextureAtlasData.<init>(TextureAtlas.java:103)
at com.badlogic.gdx.graphics.g2d.TextureAtlas.<init>(TextureAtlas.java:231)
at com.badlogic.gdx.graphics.g2d.TextureAtlas.<init>(TextureAtlas.java:226)
at com.badlogic.gdx.graphics.g2d.TextureAtlas.<init>(TextureAtlas.java:216)
at com.mygdx.mytestgame.MyTestGame.create(MyTestGame.java:21)
at com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:275)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1555)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1270)
Caused by: java.io.FileNotFoundException: shooter.atlas
at android.content.res.AssetManager.openAsset(Native Method)
at android.content.res.AssetManager.open(AssetManager.java:374)
at android.content.res.AssetManager.open(AssetManager.java:348)
at com.badlogic.gdx.backends.android.AndroidFileHandle.read(AndroidFileHandle.java:75)
at com.badlogic.gdx.graphics.g2d.TextureAtlas$TextureAtlasData.<init>(TextureAtlas.java:103)
at com.badlogic.gdx.graphics.g2d.TextureAtlas.<init>(TextureAtlas.java:231)
at com.badlogic.gdx.graphics.g2d.TextureAtlas.<init>(TextureAtlas.java:226)
at com.badlogic.gdx.graphics.g2d.TextureAtlas.<init>(TextureAtlas.java:216)
at com.mygdx.mytestgame.MyTestGame.create(MyTestGame.java:21)
at com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:275)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1555)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1270)