user494461
user494461

Reputation:

Null pointer exception in java when trying to load file

I'm following the example here http://www.bigerstaff.com/

I;ve added another class called Ball, and use an instance of it in this code

public class Ball extends Vector3 {

    public Sprite mSprite;
    public Texture mTexture;

So instead of using blockTexture and blockSprite,

blockTexture = new Texture(Gdx.files.internal("data/block.png"));
blockSprite = new Sprite(blockTexture);

I use

ball.mTexture = new Texture(Gdx.files.internal("data/block.png")); //error
ball.mSprite = new Sprite(ball.mTexture); //error

Sorry I am new to Java, but am I missing something very basic here?

Upvotes: 0

Views: 142

Answers (2)

Brtle
Brtle

Reputation: 2297

Did you create a ball object ? ball seems null.

Upvotes: 1

Gbayer
Gbayer

Reputation: 31

Switch

ball.mSprite = new Sprite(blockTexture);

for

ball.mSprite = new Sprite(ball.mTextture);

you are not creating the blockTexture object.

Upvotes: 0

Related Questions