title: Fetching list data using Model class in android
body: <p>I have two the Model class <code>Speciality</code> and <code>SubSpeciality</code> . when i am calling getsubSpecialityList it returns <code>NullpointerException</code>.</p>
  
  <p><strong>Speciality Model</strong> </p>
  
  <pre><code>public class Speciality 
  {
   public String name;
   public List&lt;SubSpeciality&gt; subSpecialityList;
   public String getname() 
   {
      return name;
   }
   public void setname(String name) 
   {
      this.name = name;
   }
   public List&lt;SubSpeciality&gt; getsubSpecialityList() 
   {
      return subSpecialityList;
   }
   public void setsubSpecialityList(List&lt;SubSpeciality&gt; subSpecialityList) 
   {
      this.subSpecialityList = subSpecialityList;
   }
  }
  </code></pre>
  
  <p><strong>SubSpeciality Model</strong></p>
  
  <pre><code>public class SubSpeciality 
  {
   public String name;
   public String getnamesub()
   {
      return name;
   }
   public void setnamesub(String name) 
   {
      this.name = name;
   }
  }
  </code></pre>
  
  <p>adding item in both model with below code</p>
  
  <pre><code> List&lt;Speciality&gt; specialityList = new ArrayList&lt;Speciality&gt;();
   List&lt;SubSpeciality&gt; subspecialityList = new ArrayList&lt;SubSpeciality&gt;();
   Speciality spe = new Speciality();
   spe.setname("Othopedic");
  
   SubSpeciality sub= new SubSpeciality();
   sub.setnamesub("---Select speciality---");
   sub.setnamesub("1");
   sub.setnamesub("2");
   sub.setnamesub("3");
   subspecialityList.add(sub);
   spe.setsubSpecialityList(subspecialityList);
   specialityList.add(spe);
  </code></pre>
  
  <p>getting error in below code</p>
  
  <pre><code>for(int j= 0;j&lt;specialityList.size();j++)
  {
     Toast.makeText(RegisterActivity.this,specialityList.get(j).getsubSpecialityList().get(j).getnamesub()+"hii",Toast.LENGTH_SHORT).show();
  }
  </code></pre>
  
  <p>Logcat output:</p>
  
  <pre><code>FATAL EXCEPTION: main Process: careers.app.com.jobssearch, PID: 29880
  java.lang.NullPointerException
      at careers.app.com.jobssearch.Activity.RegisterActivity$getSpeciality.onPostExecute(RegisterActivity.java:320)
      at careers.app.com.jobssearch.Activity.RegisterActivity$getSpeciality.onPostExecute(RegisterActivity.java:263)
      at android.os.AsyncTask.finish(AsyncTask.java:632)
      at android.os.AsyncTask.access$600(AsyncTask.java:177)
      at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:645)
      at android.os.Handler.dispatchMessage(Handler.java:102)
      at android.os.Looper.loop(Looper.java:136)
      at android.app.ActivityThread.main(ActivityThread.java:5072)
      at java.lang.reflect.Method.invokeNative(Native Method)
      at java.lang.reflect.Method.invoke(Method.java:515)
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
      at dalvik.system.NativeStart.main(Native Method)
  </code></pre>