Hi, im starting with libgdx on android and im trying to do some practices, im getting this error
E/AndroidRuntime( 1592): FATAL EXCEPTION: GLThread
E/AndroidRuntime( 1592): java.lang.NullPointerException
E/AndroidRuntime( 1592): at gdx.game.Game.render(Game.java:81)
E/AndroidRuntime( 1592): at com.badlogic.gdx.backends.android.AndroidGrap
hics.onDrawFrame(AndroidGraphics.java:449)
E/AndroidRuntime( 1592): at com.badlogic.gdx.backends.android.surfaceview
.GLSurfaceViewCupcake$GLThread.guardedRun(GLSurfaceViewCupcake.java:713)
E/AndroidRuntime( 1592): at com.badlogic.gdx.backends.android.surfaceview
.GLSurfaceViewCupcake$GLThread.run(GLSurfaceViewCupcake.java:646)
Here is my code
public class Game implements ApplicationListener {
Stage stage;
SpriteBatch spriteBatch;
muñeco pnj;
Image image;
Touchpad touchpad;
TextureRegion[] walkFrames;
float stateTime;
OrthographicCamera camera;
TextureRegion currentFrame;
Label lbl;
JoystickScreen js;
public void create() {
stage = new Stage();
Gdx.input.setInputProcessor(stage);
Skin skin = new Skin(Gdx.files.internal("data/uiskin.json"));
pnj = new muñeco(getSprites("data/sprite.png", 3, 4));
pnj.setAnims();
touchpad = new Touchpad(20, skin);
touchpad.setBounds(15, 15, 100, 100);
stage.addActor(touchpad);
}
public void render() {
Gdx.gl.glClearColor(0, 0, 0.2f, 1);
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
stage.act(Gdx.graphics.getDeltaTime());
stateTime += Gdx.graphics.getDeltaTime(); // #15
if (touchpad.getKnobPercentX() > 50) {
currentFrame = pnj.walkr.getKeyFrame(stateTime, true); // #16
}
if (touchpad.getKnobPercentX() < -50) {
currentFrame = pnj.walkl.getKeyFrame(stateTime, true); // #16
}
if (touchpad.getKnobPercentY() > 50) {
currentFrame = pnj.walku.getKeyFrame(stateTime, true); // #16
}
if (touchpad.getKnobPercentY() < -50) {
currentFrame = pnj.walkd.getKeyFrame(stateTime, true); // #16
}
spriteBatch.begin();
spriteBatch.draw(currentFrame, 100, 100); // #17
spriteBatch.end();
stage.draw();
}
public void resize(int width, int height) {
stage.setViewport(width, height, true);
}
public void pause() {
}
public void resume() {
}
public void dispose() {
stage.dispose();
}
public void escribir(String frase) {
lbl.setText(frase);
}
public static TextureRegion[] getSprites(String filepath, int col, int fil) {
Texture walkSheet = new Texture(Gdx.files.internal(filepath));
TextureRegion[][] tmp = TextureRegion.split(walkSheet, walkSheet.getWidth() / col, walkSheet.getHeight() / fil);
TextureRegion[] walkFrames = new TextureRegion[col * fil];
int index = 0;
for (int i = 0; i < col-1; i++) {
for (int j = 0; j < fil-1; j++) {
walkFrames[index++] = tmp[i][j];
}
}
return walkFrames;
}
}
The line that gives the error is:
spriteBatch.begin();
Sorry for that dirty code, i have no idea of what im doing wrong but im sure its a really noob mistake.
Hope some help and sorry for my bad english