我在手机上使用AIDE,使用libgdx引擎编写这个程序。当我运行这个程序时,它几乎立刻崩溃。我没有机会做太多事情,但我已经把问题缩小到尝试加载自己的照片。当我删除/禁用代码"Texture(Gdx.files.internal("button_center.png");"时,程序就可以运行了。另一张图片是在项目启动时预装的,没有任何问题。我试着将我的图像移动到与工作图像相同的文件夹中,并刷新了构建,但应用程序仍然崩溃。
这是代码:
package pavlov.murderdoggyalpha;
import com.badlogic.gdx.*;
import com.badlogic.gdx.graphics.*;
import com.badlogic.gdx.graphics.g2d.*;
import pavlov.murderdoggyalpha.*;
public class MyGdxGame implements ApplicationListener
{
Texture texture;
Texture butDownLeft;
Texture butLeft;
Texture butUpLeft;
Texture butDown;
Texture butCenter;
Texture butUp;
Texture butDownRight;
Texture butRight;
Texture butUpRight;
SpriteBatch batch;
int touchX;
int touchY;
@Override
public void create()
{
texture = new Texture(Gdx.files.internal("android.jpg"));
butCenter = new Texture(Gdx.files.internal("button_center.png"));
batch = new SpriteBatch();
}
@Override
public void render()
{
Gdx.gl.glClearColor(1, 1, 1, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
batch.draw(texture, touchX, touchY,
Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
if (Gdx.input.justTouched());
{
touchX = Gdx.input.getX();
touchY = Gdx.input.getY();
}
batch.end();
}
@Override
public void dispose()
{
}
@Override
public void resize(int width, int height)
{
}
@Override
public void pause()
{
}
@Override
public void resume()
{
}
}
我相信这就是错误日志。我提前道歉,我是新手。
这对我来说很突出:
导致原因:java.io.IOException:无法仅加载像素图8bit。
剩下的是:。
10-23 19:48:59.061 3786 4066 E AndroidRuntime致命异常:GLThread 3057110-23 19:48:59.061 3786 4066 E AndroidRuntime进程:pavlov.murderdoggyalpha,PID:378610-23 19:48:59.061 3786 4066 E AndroidRuntime com.badlogic.gdx.utils.GdxRuntime异常:无法加载文件:button_center.png10-23 19:48:59.061 3786 4066 E AndroidRuntime,网址为com.badlogic.gdx.graphics.Pixmap.(Pixmap.java:140)10-23 19:48:59.061 3786 4066 E AndroidRuntime,网址为com.badlogic.gdx.graphics.glutils.FileTextureData.reprepare(FileTextureData_java:64)10-23 19:48:59.061 3786 4066 E AndroidRuntime,网址为com.badlogic.gdx.ggraphics.Texture.load(Texture.java:130)10-23 19:48:59.061 3786 4066 E AndroidRuntime,网址为com.badlogic.gdx.graphics.Texture。(Texture.java:121)10-23 19:48:59.061 3786 4066 E AndroidRuntime,网址为com.badlogic.gdx.graphics.Texture。(Texture.java:100)10-23 19:48:59.061 3786 4066 E AndroidRuntime,网址为com.badlogic.gdx.graphics.Texture。(Texture.java:92)10-23 19:48:59.061 3786 4066 E AndroidRuntime at pavlov.murderdogyalpha.MyGdxGame$0$debug.create(MyGdxGame.java:35)10-23 19:48:59.061 3786 4066 E AndroidRuntime at pavlov.murderdogyalpha.MyGdxGame.create(MyGdxGame.java)10-23 19:48:59.061 3786 4066 E AndroidRuntime,网址为com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:236)10-23 19:48:59.061 3786 4066 E AndroidRuntime at android.ongle.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1519)10-23 19:48:59.061 3786 4066 E AndroidRuntime at android.ongle.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)10-23 19:48:59.061 3786 4066 E AndroidRuntime由java.io.io引起异常:无法仅加载像素图8bit10-23 19:48:59.061 3786 4066 E AndroidRuntime,网址为com.badlogic.gdx.gid.Gdx2DPixmap.(Gd2DPixmap.java:57)10-23 19:48:59.061 3786 4066 E AndroidRuntime,网址为com.badlogic.gdx.graphics.Pixmap.(Pixmap.java:138)10-23 19:48:59.061 3786 4066 E AndroidRuntime。。。10个以上10-23 19:48:59.061 3786 4066 E AndroidRuntime致命异常:GLThread 3057110-23 19:48:59.061 3786 4066 E AndroidRuntime进程:pavlov.murderdoggyalpha,PID:378610-23 19:48:59.061 3786 4066 E AndroidRuntime com.badlogic.gdx.utils.GdxRuntime异常:无法加载文件:button_center.png10-23 19:48:59.061 3786 4066 E AndroidRuntime,网址为com.badlogic.gdx.graphics.Pixmap.(Pixmap.java:140)10-23 19:48:59.061 3786 4066 E AndroidRuntime,网址为com.badlogic.gdx.graphics.glutils.FileTextureData.reprepare(FileTextureData_java:64)10-23 19:48:59.061 3786 4066 E AndroidRuntime,网址为com.badlogic.gdx.ggraphics.Texture.load(Texture.java:130)10-23 19:48:59.061 3786 4066 E AndroidRuntime,网址为com.badlogic.gdx.graphics.Texture。(Texture.java:121)10-23 19:48:59.061 3786 4066 E AndroidRuntime,网址为com.badlogic.gdx.graphics.Texture。(Texture.java:100)10-23 19:48:59.061 3786 4066 E AndroidRuntime,网址为com.badlogic.gdx.graphics.Texture。(Texture.java:92)10-23 19:48:59.061 3786 4066 E AndroidRuntime at pavlov.murderdogyalpha.MyGdxGame$0$debug.create(MyGdxGame.java:35)10-23 19:48:59.061 3786 4066 E AndroidRuntime at pavlov.murderdogyalpha.MyGdxGame.create(MyGdxGame.java)10-23 19:48:59.061 3786 4066 E AndroidRuntime,网址为com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:236)10-23 19:48:59.061 3786 4066 E AndroidRuntime at android.ongle.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1519)10-23 19:48:59.061 3786 4066 E AndroidRuntime at android.ongle.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)10-23 19:48:59.061 3786 4066 E AndroidRuntime由java.io.io引起异常:无法仅加载像素图8bit10-23 19:48:59.061 3786 4066 E AndroidRuntime,网址为com.badlogic.gdx.gid.Gdx2DPixmap.(Gd2DPixmap.java:57)10-23 19:48:59.061 3786 4066 E AndroidRuntime,网址为com.badlogic.gdx.graphics.Pixmap.(Pixmap.java:138)10-23 19:48:59.061 3786 4066 E AndroidRuntime。。。10个以上10-2
通过谷歌搜索"原因是:java.io.IOException:只能加载pixmap 8bit"后,我发现由于某种原因,它在加载16位png图像时遇到了问题。我不知道如何将其更改为8位图像,所以我去了lunapics,将文件扩展名换成了gif。该应用程序现在运行良好。