title: Getting NullPointerException when accessing a variable in a Java class
body: <p>I have a problem when setting a variable inside a Java class</p>
  
  <p>Here is my code </p>
  
  <p>This is where I create the instances (IdeaInfo is a class that acts similar to a Struct):</p>
  
  <pre><code>IdeaInfo[] IDEAS = new IdeaInfo[100];
  String[] TITLES = new String[100];
  </code></pre>
  
  <p>This is the function that will use those instances:</p>
  
  <pre><code>    try {
          while ((line = reader.readLine()) != null) {
              sb.append(line + "\n");
              // This is adding title to array Ideas and Titles
              if(mode % 3 == 0)   {
                  IDEAS[ideas_pos].setTitle(sb.toString());
                  TITLES[titles_pos] = sb.toString();
                  titles_pos++;
                  mode++;
              }
              // This is adding the content to array Ideas
              else if(mode % 3 == 1)  {
                  IDEAS[ideas_pos].mContent = sb.toString();
                  mode++;
              }
              // This is adding the rating to array Ideas
              else if(mode % 3 == 2)  {
                  IDEAS[ideas_pos].mRating = Float.valueOf(sb.toString().trim()).floatValue();
                  ideas_pos++;
                  mode++;
              }
          }
      }
  </code></pre>
  
  <p>This is what I have inside IdeaInfo class:</p>
  
  <pre><code>public class IdeaInfo {
  
      public String mTitle = new String();        // Store the Idea's title
      public String mContent = new String();  // Store the Idea's title
      public float mRating;       // Store the Idea's Rating
  
      /*
       * Function that set the Idea's title
       */
      public void setTitle(String temp){
        mTitle = temp;
      }
  }
  </code></pre>
  
  <p>Apparently, the error occurred inside the try, exactly at <code>IDEAS[ideas_pos].setTitle(sb.toString());</code>
  The debugger indicated that I am accessing a NullPointerException, this does not really make any sense to me since I already initialize those variables in the class.</p>
  
  <p>By the way, I initialized <code>ideas_pos</code> to 0.</p>