title: Java - Null pointer exception on method call
body: <p>I am using LibGDX to build a game for android.
  I am getting a null pointer exception in this class but I dont know why (check the comments).</p>
  
  <pre><code>public class ScoreFont {
      private Texture _numbers[];
      private int _number;
  
      public ScoreFont(){
         //Load font
         for(int i = 0; i &lt;= 9; i++){
              _numbers = new Texture[10];
              _numbers[i] = new Texture("font_"+i+".png");
             /*the line above works fine. if I use if(_number[i] != null) System.out.println("loaded"); it will print*/
  
          }
          _number = 0;
      }
  
      public void setNumber(int number){
          _number = number;
      }
  
      public void draw(SpriteBatch sb, float x, float y, float width, float height){
          String numberString = Integer.toString(_number);
  
          int numDigits = numberString.length();
          float totalWidth = width * numDigits;
  
          //Draw digits
          for(int i = 0; i &lt; numDigits; i++){
              int digit = Character.getNumericValue(numberString.charAt(i));
  
              /*I get a null pointer exception when this method or the dispose() method are called. The _numbers[digit] == null, or even if I switch it for _numbers[0] it is still null. Why?*/
              sb.draw(_numbers[digit], x - totalWidth/2 + i*width, y - height/2, width, height);
          }
      }
  
      public void dispose(){
          //I get null pointer exception
          for(Texture texture: _numbers){
              texture.dispose();
          }
      }
  }
  </code></pre>
  
  <p>What may be happening here? The constructor of this function has to be called always before any method and this will guarantee that the textures are always loaded right? So why am I getting a null pointer exception?</p>
  
  <p>Thanks!</p>