Java 平铺贴图集纹理区域提供NullPointerException

Java 平铺贴图集纹理区域提供NullPointerException,java,android,libgdx,tile,region,Java,Android,Libgdx,Tile,Region,我在将纹理区域设置为平铺贴图时遇到一些问题。它给了我NullPointerException,我不知道为什么 下面是一些代码: TiledMapTile coinTile; public void show () { mapTexture1 = new Texture(Gdx.files.internal("maps/other/texture1.png")); TextureRegion mapTexture1Region = new TextureRegion(mapTe

我在将纹理区域设置为平铺贴图时遇到一些问题。它给了我
NullPointerException
,我不知道为什么

下面是一些代码:

TiledMapTile coinTile;

public void show () {
    mapTexture1 = new Texture(Gdx.files.internal("maps/other/texture1.png"));

    TextureRegion mapTexture1Region = new TextureRegion(mapTexture1, 32, 0, 16, 16);
    coinTile.setTextureRegion(mapTexture1Region);
}
下面是错误:

04-09 21:57:18.222:E/AndroidRuntime(7792):java.lang.NullPointerException
04-09 21:57:18.222:E/AndroidRuntime(7792):在com.never.mind.screens.GameScreen.show(GameScreen.java:225)上

这就引出了这条线:

coinTile.setTextureRegion(mapTexture1Region);

通常,当您没有初始化代码中的某些内容时,就会发生NullPointerException

由于您没有提供完整的代码,我只能给出您的建议。 就像你做的那样

mapTexture1 = new Texture(Gdx.files.internal("maps/other/texture1.png"));
你也应该

coinTile = new TiledMapTile () {
@Override
public int getId() {
    return 0;
}

@Override
public void setId(int id) {

}

@Override
public BlendMode getBlendMode() {
    return null;
}

@Override
public void setBlendMode(BlendMode blendMode) {

}

@Override
public TextureRegion getTextureRegion() {
    return null;
}

@Override
public void setTextureRegion(TextureRegion textureRegion) {

}

@Override
public float getOffsetX() {
    return 0;
}

@Override
public void setOffsetX(float offsetX) {

}

@Override
public float getOffsetY() {
    return 0;
}

@Override
public void setOffsetY(float offsetY) {

}

@Override
public MapProperties getProperties() {
    return null;
}

}
顺便说一下,请阅读特定参数的API


由于您不熟悉java read以掌握空指针

您可以发布整个stacktrace吗。另外,mapTexture1定义在哪里?如您所问,已更新(我是java新手-我假设stacktrace的意思是确切的错误和代码行?)运行快速调试日志以检查
Gdx.files.internal(“maps/other/texture1.png”)
返回的不是
null
我没有得到关于此纹理的任何信息-只得到以下信息:Thread[GLThread 10](挂起(异常NullPointerException))GLSurfaceView$GLThread.run()行:1122tanks。当我添加您发布的代码时,它停止在coinTile中返回nullpointerexception。然而,现在当我尝试用任何矩形更新空数组时,它会给出nullpointerexception:/当我找到如何修复它并确保它工作时,我会将您的答案标记为解决方案:)请打开一个新的问题主题,就像问其他问题一样。提供尽可能多的信息,以获得关于堆栈溢出的最佳结果