-1

I've started using the Lib GDX AssetManager instead of the "normal" way to import textures. However, when experimenting with it, I quickly encountered a NullPointerException error. Here is the code:

    assets = Generals.getAssetManager();
    assets.load("Characters/c.pack", TextureAtlas.class);
    assets.finishLoading();
    TextureAtlas atlas = assets.get("Characters/c.pack", TextureAtlas.class);
    atlas.findRegion("PriestOverworld3");
    Array<TextureRegion> frames = new Array<TextureRegion>();
    Texture testtex = new Texture("Characters/c.png");
    TextureRegion test = new TextureRegion(testtex);
    for (int i = 0; i < 3; i++) {
        System.out.println(i);
        frames.add(new TextureRegion(getTexture(), i * 16, 0, 16, 16));
    }
    playerStasis = new Animation<>(0.2f, frames);

I get a NullPointerException at the line

frames.add(new TextureRegion(getTexture(), i * 16, 0, 16, 16));

The error:

Exception in thread "LWJGL Application" java.lang.NullPointerException
    at com.badlogic.gdx.graphics.g2d.TextureRegion.setRegion(TextureRegion.java:82)
    at com.badlogic.gdx.graphics.g2d.TextureRegion.<init>(TextureRegion.java:53)
    at Project.sprites.Player.<init>(Player.java:55)

TextureRegion:

// TextureRegion.java:53
setRegion(x, y, width, height);
...
// TextureRegion.java:82
float invTexWidth = 1f / texture.getWidth();
JasperMW
  • 465
  • 3
  • 7
  • 22

1 Answers1

2

IT looks like you are finding the atlasRegion and not setting it to a variable.

Try using this

frames.add(new TextureRegion(atlas.findRegion("PriestOverworld3"), i * 16, 0, 16, 16));
dfour
  • 1,376
  • 1
  • 12
  • 16