title: Arrays & Null Pointer Exception Issue
body: <p>Hi I'm a new computer engineering student and studying java, my problem may be very easy to solve but I tried hard to find the solution and could not, my final exam is coming so I'm in hurry and need help.</p>
  
  <p>I got this error message;</p>
  
  <pre><code>Exception in thread "main" java.lang.NullPointerException
      at Lab8.ModelingAgency.addModel(ModelingAgency.java:45)
      at Lab8.ModelingApp.main(ModelingApp.java:45)
  </code></pre>
  
  <p>What I'm trying to do is, create a modeling agency class that has models array which has no models. Create 2nd array with models. Add the 2nd array's models to modeling agency object via addModel method. Give an error if the modeling agency has models more than 4.</p>
  
  <p>I got this <code>NullPointerException</code> error when assign the model to an arrays element in the part:</p>
  
  <pre><code>this.modelList[modelCount] = new Model(modelp);
  this.modelCount++;
  </code></pre>
  
  <p>Anything related with modelList gives a null pointer exception</p>
  
  <p>I wrote The "default" gay models to get rid of np exceptions but inializing the arrays with these did not fix the problem either. </p>
  
  <p>I could not try the code because of the null pointer exception so maybe there would be more errors I'll try to fix them as soons as I get rid of null pointer exception.</p>
  
  <pre><code>public class ModelingAgency {
  
      // properties
      private String name;
      private int modelCount;
      private Model[] modelList;
  
      // contructors
      public ModelingAgency ( String name) {
          this.name = name;
          Model[] modelList = new Model[4];
          modelCount = 0;
  
          // for ( Model model: modelList){
  
          for ( int i = 0; i &lt; modelList.length; i++)
              modelList[i] = new Model ("Default", "Gay", 69);
          }
  
  
      // methods
      public int addModel ( Model modelp ) {
  
          if (modelp == null)
              return -4;
          if ( this.modelCount &gt; 4){
              //System.out.println("Can't add too much models.");
              return -1;
          }
          for ( int i = 0; i &lt; modelCount; i++){
              if (modelp.equals(this.modelList[i])) {
                  return -2;
              }   
          }
          if (!(modelp.checkAge())){
              return -3;
          }
  
          this.modelList[modelCount] = modelp; // LINE OF NULL POINTER EXCEPTION
          this.modelCount++;
          return 0;
      }
  
      public String toString (){
          String result = "";
          for (int i = 0; i &lt; modelCount; i++ ){
              result+= " " + this.modelList[i] + " \n";
          }
          return result;
      }
  
  }
  </code></pre>