title: Drawing sprites in libgdx
body: <p>I get a NullPoinerExecption when calling </p>
  
  <pre><code>enemy.getSprite().draw(batch);
  </code></pre>
  
  <p>Where do I have to initialize my sprite? 
  It works in main class, but if I try to initialize texture and sprite in Enemy constructor then it gives me error.</p>
  
  <p>Here's my <strong>main class</strong>:</p>
  
  <pre><code>  public class SpaceShooter implements ApplicationListener {
  
       private SpriteBatch batch;
          private Texture texture;
          private Sprite sprite, spriteEnemy;
          private Player p;
          private Enemy enemy;
  
          @Override
          public void create() {       
              p = new Player();
              enemy = new Enemy(spriteEnemy);
  
  
              float w = Gdx.graphics.getWidth();
              float h = Gdx.graphics.getHeight();
  
              batch = new SpriteBatch();
  
              texture = new Texture(Gdx.files.internal("craft.png"));
              sprite = new Sprite(texture);
              sprite.setPosition(w/2 -sprite.getWidth()/2, h/2 - sprite.getHeight()/2);
  
              // Adding enemy sprite
  
          }
  
          @Override
          public void dispose() {
              batch.dispose();
              texture.dispose();
          }
  
          @Override
          public void render() {        
              Gdx.gl.glClearColor(1, 1, 1, 1);
              Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
  
              // moving sprite left and right
  
  
              batch.begin();
              sprite.draw(batch);
              enemy.getSprite().draw(batch);          
              batch.end();
          }
  </code></pre>
  
  <p><strong>Enemy class</strong></p>
  
  <pre><code> public class Enemy {
  
      private Sprite sprite;
      private Texture texture;
  
  
      boolean gameOver;
  
      public Enemy(Sprite sprite){
  
          this.sprite = new Sprite();
  
      }
  
      public Sprite getSprite(){
          return sprite;
      }
  
      public void create() {
          texture = new Texture(Gdx.files.internal("enemy.png"));
          sprite = new Sprite(texture);
          this.sprite.setPosition(100, 200);
      }
  </code></pre>