[英]Null pointer exception in java when trying to load file
I'm following the example here http://www.bigerstaff.com/ 我在这里跟随示例http://www.bigerstaff.com/
I;ve added another class called Ball, and use an instance of it in this code 我添加了另一个名为Ball的类,并在此代码中使用它的一个实例
public class Ball extends Vector3 {
public Sprite mSprite;
public Texture mTexture;
So instead of using blockTexture and blockSprite
, 因此blockTexture and blockSprite
使用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? 抱歉,我是Java的新手,但是我在这里错过了一些非常基本的东西吗?
Did you create a ball
object ? 您是否创建了ball
对象? ball
seems null. ball
似乎为空。
Switch 开关
ball.mSprite = new Sprite(blockTexture);
for 对于
ball.mSprite = new Sprite(ball.mTextture);
you are not creating the blockTexture object. 您没有在创建blockTexture对象。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.