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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
| 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(); if (touchpad.getKnobPercentX() > 50) { currentFrame = pnj.walkr.getKeyFrame(stateTime, true); } if (touchpad.getKnobPercentX() < -50) { currentFrame = pnj.walkl.getKeyFrame(stateTime, true); } if (touchpad.getKnobPercentY() > 50) { currentFrame = pnj.walku.getKeyFrame(stateTime, true); } if (touchpad.getKnobPercentY() < -50) { currentFrame = pnj.walkd.getKeyFrame(stateTime, true); } spriteBatch.begin(); spriteBatch.draw(currentFrame, 100, 100); 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