-1

Heres the console error I'm getting:

Exception in thread "LWJGL Application" java.lang.NullPointerException
at com.dakotapederson.slingshotsteve.SlingshotSteve.render(SlingshotSteve.java:30)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:206)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:114)

And here is the code:

package com.dakotapederson.slingshotsteve;

import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;

public class SlingshotSteve implements ApplicationListener {
   // Creates our 2D images
   private SpriteBatch batch;
   private TextureRegion backgroundTexture;
   private Texture texture;


@Override
public void create() {


    Texture texture = new Texture(Gdx.files.internal("background.jpg"));
    backgroundTexture = new TextureRegion(texture, 20, 20, 50, 50);

}


@Override
public void render() {  
      Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
      batch.begin();
      batch.draw(backgroundTexture, 0, 0); 
      batch.end();

}

@Override
public void resize(int width, int height) {

}

@Override
public void pause() {

}

@Override
public void resume() {

}

@Override
public void dispose() {
       batch.dispose();
       texture.dispose();
}
}

What do the console errors exactly mean? Because if theirs an error in the code I need to know what it is. Also, since I'm new at this, please describe the error in the code with as much clarity as possible.

Dakota
  • 115
  • 2
  • 11
  • 2
    possible duplicate of [What is a NullPointerException, and how do I fix it?](http://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) – greg-449 Aug 26 '14 at 15:50
  • I wouldn't consider it a duplicate because thats asking for something complicated that I wouldn't understand. I'm asking for something that I can understand and is at my level. – Dakota Aug 26 '14 at 16:03
  • This is not a duplicate. I have no idea what the answers on the other question even mean and I don't understand a single thing. The question I made is for beginners. This is why this website sucks. – Dakota Aug 26 '14 at 16:20
  • 1
    @Dakota you should learn how to debug, before judging this website. The exception text tells you that a `Nullpointer` occurs at line 30 and line 30 is `batch.begin()`, so it seems like `batch` is `null`. So take a look at every occurrence of `batch` and you will see, that you never assign it a value. – Robert P Aug 27 '14 at 06:20

1 Answers1

0

You should read basic tutorial: https://github.com/libgdx/libgdx/wiki/A-simple-game

You are missing this line in create():

batch = new SpriteBatch();
Yuraj
  • 3,185
  • 1
  • 23
  • 42