R
R
ratatyq2016-11-24 20:54:17
Java
ratatyq, 2016-11-24 20:54:17

Why does this code throw a NullPointerException?

Hello, this constructor code does not want to work, it throws a NullPointerException:

public AnimationsPlayer(Texture texture, int width, int height, boolean isTime, int col, int row) { // Last version constructor AnimationPlayer
        TextureRegion[][] frames = TextureRegion.split(texture, width, height);


        TextureAtlas[] atlas = new TextureAtlas[row];

        for(int i = 0; i < row; i++) {
            for(int j = 0; j < col; j++) {
                atlas[i].addRegion("frame_" + j, frames[i][j]);

                //System.out.println("[Debugg]" + atlas.findRegion("frame_" + j).getRegionX());
            }
        }
    }

the compiler complains about the following line:
"atlas[i].addRegion("frame_" + j, frames[i][j]);"

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Oparin, 2016-11-24
@losse_narmo

Because you are creating a TextureAtlas[] atlas array, but there are no objects in it, only nulls

S
SagePtr, 2016-11-24
@SagePtr

Check if the following objects exist:
atlas, atlas[i], frames, frames[i], frames[i][j]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question