title: Java LWJGL/Slick Util Java Null Pointer Exception Error (Texture Loading)
body: <p>I have been having some issues with loading Textures in LWJGL/Slick Util.  I am receiving this error in the <code>texture.bind()</code> method. I would also like advice as to how to improve my code if improvement is needed. Here it is:  </p>
  
  <p>The Sprite Class:</p>
  
  <pre><code>package geniushour.engine.animation;
  
  import static org.lwjgl.opengl.GL11.*;
  
  import java.io.IOException;
  
  import org.newdawn.slick.opengl.Texture;
  
  public class Sprite {
  
      private float sx;
      private float sy;
      private Texture texture;
  
      public Sprite(float sx, float sy, Texture texture) throws IOException{
          this.texture = texture;
          this.sx = sx;
          this.sy = sy;
      }
  
      public void render(){
          texture.bind();
          glBegin(GL_QUADS);
          glTexCoord2f(0,0);
          glVertex2f(0,0);
          glTexCoord2f(1,0);
          glVertex2f(0,sy);
          glTexCoord2f(1,1);
          glVertex2f(sx,sy);
          glTexCoord2f(0,1);
          glVertex2f(sx,0);
          glEnd();
      }
  
      public float getSX(){
          return sx;
      }
      public float getSY(){
          return sy;
      }
      public Texture getTexture(){
          return texture;
      }
      public void setSX(float sx){
          this.sx = sx;
      }
      public void setSY(float sy){
          this.sy = sy;
      }
      /*public void setSpriteTexture(String key) throws IOException{
          this.texture = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("img/"+key+".png"));
      }*/
  }
  </code></pre>
  
  <p>The GameObject Class:</p>
  
  <pre><code>package geniushour.gameobject;
  
  import static org.lwjgl.opengl.GL11.glPopMatrix;
  import static org.lwjgl.opengl.GL11.glPushMatrix;
  import static org.lwjgl.opengl.GL11.glTranslatef;
  
  import java.io.IOException;
  
  import org.newdawn.slick.opengl.Texture;
  
  import geniushour.engine.animation.Sprite;
  
  public abstract class GameObject {
  
      protected float x;
      protected float y;
      protected float sx;
      protected float sy;
      protected Sprite spr;
      protected int type;
      protected static final int PLAYER_ID = 0;
      protected static final int ENEMY_ID = 1;
      protected static final int ITEM_ID = 2;
      protected static final int ENTITY_SIZE = 64;
      protected static final int ITEM_SIZE = 16;
      protected boolean[] flags = new boolean[1];
  
      public void update(){}
      public void render(){
          glPushMatrix();
          glTranslatef(x,y,0);
          spr.render();
          glPopMatrix();
      }
      public float getX(){
          return x;
      }
      public float getY(){
          return y;
      }
      public float getSX(){
          return spr.getSX();
      }
      public float getSY(){
          return spr.getSY();
      }
      public int getType(){
          return type;
      }
      public boolean getRemove(){
          return flags[0];
      }
      public void remove(){
          flags[0] = true;
      }
      /*protected void setTexture(String key) throws IOException{
          spr.setSpriteTexture(key);
      }*/
      public Texture getTexture(){
          return spr.getTexture();
      }
      protected void init(float x, float y, float sx, float sy,Texture texture,int type) throws IOException{
          this.x = x;
          this.y = y;
          this.type = type;
          this.spr = new Sprite(sx,sy,texture);
      }
  }
  </code></pre>
  
  <p>The Player Class:</p>
  
  <pre><code>package geniushour.gameobject.entity;
  
  import java.io.IOException;
  
  import org.lwjgl.input.Keyboard;
  import org.newdawn.slick.opengl.Texture;
  
  import geniushour.game.Inventory;
  import geniushour.game.Stats;
  import geniushour.gameobject.GameObject;
  import geniushour.gameobject.item.Item;
  
  public class Player extends GameObject {
  
      private Stats stats;
      private Inventory inv;
      private int stamina;
      private int maxStamina = 150;
  
      public Player(float x, float y, Texture texture) throws IOException{
          init(x,y,ENTITY_SIZE,ENTITY_SIZE,texture,PLAYER_ID);
          stats = new Stats(0,true);
          inv = new Inventory(9);
          stamina = maxStamina;
      }
      public void update(){
          if(Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) &amp;&amp; stamina &gt; 0){
              stamina--;
          }
          else if(!Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)){
              stamina++;
              if(stamina &gt; maxStamina){
                  stamina = maxStamina;
              }
          }
      }
      public void getInput(){
          if(Keyboard.isKeyDown(Keyboard.KEY_W)){
              if(Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) &amp;&amp; stamina &gt; 0){
                  move(0,1.5);
              }
              else{
                  move(0,1);
              }
          }
          if(Keyboard.isKeyDown(Keyboard.KEY_S)){
              if(Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) &amp;&amp; stamina &gt; 0){
                  move(0,-1.5);
              }
              else{
                  move(0,-1);
              }
          }
          if(Keyboard.isKeyDown(Keyboard.KEY_A)){
              if(Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) &amp;&amp; stamina != 0){
                  move(-1.5,0);
              }
              else{
                  move(-1,0);
              }
          }
          if(Keyboard.isKeyDown(Keyboard.KEY_D)){
              if(Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) &amp;&amp; stamina != 0){
                  move(1.5,0);
              }
              else{
                  move(1,0);
              }
          }
      }
      public Texture getTexture(){
          return getTexture();
      }
      private void move(double magX, double magY){
          x += getSpeed() * magX;
          y += getSpeed() * magY;
      }
      private int getSpeed(){
          return stats.getPlayerSpeed();
      }
      @SuppressWarnings("unused")
      private int getLevel(){
          return stats.getLevel();
      }
      @SuppressWarnings("unused")
      private int getXP(){
          return stats.getXP();
      }
      public int getMaxHP(){
          return stats.getMaxHP();
      }
      public int getCurrentHealth(){
          return stats.getCurrentHealth();
      }
      public int getStrength(){
          return stats.getStrength();
      }
      public int getMagic(){
          return stats.getMagic();
      }
      public void addXP(int amt){
          stats.addXP(amt);
      }
      public void addHP(int amt){
          stats.addHP(amt);
      }
      public void addItem(Item item){
          inv.add(item);
      }
  }
  </code></pre>
  
  <p>The Game Class:</p>
  
  <pre><code>package geniushour.game;
  
  import java.io.IOException;
  import java.util.ArrayList;
  
  import org.newdawn.slick.opengl.Texture;
  
  import geniushour.gameobject.*;
  import geniushour.gameobject.entity.*;
  import geniushour.gameobject.item.*;
  
  public class Game {
  
      private ArrayList&lt;GameObject&gt; obj;
      private ArrayList&lt;GameObject&gt; remove;
      private Player p;             private Texture pTexture;
      private ItemEssence essence;  private Texture eTexture;
      private EnemyBlob blob;       private Texture bTexture;
  
      public Game() throws IOException{
          obj = new ArrayList&lt;GameObject&gt;();
          remove = new ArrayList&lt;GameObject&gt;();
          setTexture(pTexture,"raptor");
          setTexture(eTexture,"essence");
          setTexture(bTexture,"blob");
  
          p = new Player(250,250,pTexture);
          essence = new ItemEssence(400, 400, eTexture, p);
          blob = new EnemyBlob(300,500,bTexture, 1);
  
          obj.add(essence);
          obj.add(p);
          obj.add(blob);
      }
  
      public void getInput(){
          p.getInput();
      }
      public void update(){
          for(GameObject go : obj){
              if(!go.getRemove()){
                  go.update();
              }
              else{
                  remove.add(go);
              }
          }
          for(GameObject go : remove){
              obj.remove(go);
          }
      }
      public void render(){
          for(GameObject go : obj){
              go.render();
          }
      }
  
      public ArrayList&lt;GameObject&gt; sphereCollide(float x, float y, float radius){
          ArrayList&lt;GameObject&gt; res = new ArrayList&lt;GameObject&gt;();
          for(GameObject go : obj){
              if(Util.dist(go.getX(),x,go.getY(),y) &lt; radius){
                  res.add(go);
              }
          }
          return res;
      }
      private void setTexture(Texture texture, String key){
  
      }
  }
  </code></pre>
  
  <p>The error occurs in the Sprite class, the first block of code.</p>