title: Arraylist error in class in my Android
body: <p>I have created two class. One of which has reference to another:</p>
  
  <pre><code>public class SCHOOL {
  
  private String schoolid;
  private String schoolname;
  private List&lt;STUDENT&gt; students;
  
  }
  
  //getters and setters for schoolid and schoolname;
  
  
  public void setStudents(List&lt;STUDENT&gt; students) {
      this.students = students;
  }
  
  
  public List&lt;STUDENT&gt; getStudents() {
      return this.students;
  }
  
  public void addStudent(String names, String age) {
      STUDENT student = new STUDENT();
      student.setNames(names);
      student.setAge(age);
      students.add(student);
  
  }
  
  
  public class STUDENT {
  
  private String names;
  private String age;
  
  
  
  public String getNames() {
      return names;
  }
  
  public void setNames(String names) {
      this.names = names;
  }
  
  public String getAge() {
      return age;
  }
  
  public void setAge(String age) {
      this.age = age;
  }
  }
  </code></pre>
  
  <p>The following is my main class:</p>
  
  <pre><code>    public class MainActivity extends AppCompatActivity {
  
      static final String tag = "Tag Activity";
      List&lt;STUDENT&gt; studentList;
  
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
  
      super.onCreate(savedInstanceState);
      //setContentView(R.layout.activity_main);
  
      SCHOOL school = new SCHOOL();
      school.setStudents(studentList);
      List&lt;STUDENT&gt; students = school.getStudents();
  
  
      school.addStudent("kent", "43");
      school.addStudent("Winnie", "42");
      school.addStudent("Dennis", "41");
  
      studentList.add((STUDENT) students);
      Log.d(tag, String.valueOf(studentList));
      .......
  </code></pre>
  
  <p>The following is my error log from logical:</p>
  
  <blockquote>
    <p>11-01 21:25:24.348 3049-3049/com.example.spidey.jsontosql W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0xa4cb4b20)
    11-01 21:25:24.360 3049-3049/com.example.spidey.jsontosql E/AndroidRuntime: FATAL EXCEPTION: main
    11-01 21:25:24.360 3049-3049/com.example.spidey.jsontosql E/AndroidRuntime: Process: com.example.spidey.jsontosql, PID: 3049
    11-01 21:25:24.360 3049-3049/com.example.spidey.jsontosql E/AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.spidey.jsontosql/com.example.spidey.jsontosql.MainActivity}: java.lang.NullPointerException
    11-01 21:25:24.360 3049-3049/com.example.spidey.jsontosql E/AndroidRuntime:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
    11-01 21:25:24.360 3049-3049/com.example.spidey.jsontosql E/AndroidRuntime:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
    11-01 21:25:24.360 3049-3049/com.example.spidey.jsontosql E/AndroidRuntime:     at android.app.ActivityThread.access$800(ActivityThread.java:135)
    11-01 21:25:24.360 3049-3049/com.example.spidey.jsontosql E/AndroidRuntime:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
    11-01 21:25:24.360 3049-3049/com.example.spidey.jsontosql E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:102)
    11-01 21:25:24.360 3049-3049/com.example.spidey.jsontosql E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:136)
    11-01 21:25:24.360 3049-3049/com.example.spidey.jsontosql E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5001)
    11-01 21:25:24.360 3049-3049/com.example.spidey.jsontosql E/AndroidRuntime:     at java.lang.reflect.Method.invokeNative(Native Method)
    11-01 21:25:24.360 3049-3049/com.example.spidey.jsontosql E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Method.java:515)
    11-01 21:25:24.360 3049-3049/com.example.spidey.jsontosql E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
    11-01 21:25:24.360 3049-3049/com.example.spidey.jsontosql E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
    11-01 21:25:24.360 3049-3049/com.example.spidey.jsontosql E/AndroidRuntime:     at dalvik.system.NativeStart.main(Native Method)
    11-01 21:25:24.360 3049-3049/com.example.spidey.jsontosql E/AndroidRuntime:  Caused by: java.lang.NullPointerException
    11-01 21:25:24.360 3049-3049/com.example.spidey.jsontosql E/AndroidRuntime:     at com.example.spidey.jsontosql.SCHOOL.addStudent(SCHOOL.java:50)
    11-01 21:25:24.360 3049-3049/com.example.spidey.jsontosql E/AndroidRuntime:     at com.example.spidey.jsontosql.MainActivity.onCreate(MainActivity.java:35)
    11-01 21:25:24.360 3049-3049/com.example.spidey.jsontosql E/AndroidRuntime:     at android.app.Activity.performCreate(Activity.java:5231)
    11-01 21:25:24.360 3049-3049/com.example.spidey.jsontosql E/AndroidRuntime:     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
    11-01 21:25:24.360 3049-3049/com.example.spidey.jsontosql E/AndroidRuntime:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
    11-01 21:25:24.360 3049-3049/com.example.spidey.jsontosql E/AndroidRuntime:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233) 
    11-01 21:25:24.360 3049-3049/com.example.spidey.jsontosql E/AndroidRuntime:     at android.app.ActivityThread.access$800(ActivityThread.java:135) 
    11-01 21:25:24.360 3049-3049/com.example.spidey.jsontosql E/AndroidRuntime:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 
    11-01 21:25:24.360 3049-3049/com.example.spidey.jsontosql E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:102) 
    11-01 21:25:24.360 3049-3049/com.example.spidey.jsontosql E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:136) 
    11-01 21:25:24.360 3049-3049/com.example.spidey.jsontosql E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5001) 
    11-01 21:25:24.360 3049-3049/com.example.spidey.jsontosql E/AndroidRuntime:     at java.lang.reflect.Method.invokeNative(Native Method) 
    11-01 21:25:24.360 3049-3049/com.example.spidey.jsontosql E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Method.java:515) 
    11-01 21:25:24.360 3049-3049/com.example.spidey.jsontosql E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785) 
    11-01 21:25:24.360 3049-3049/com.example.spidey.jsontosql E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) 
    11-01 21:25:24.360 3049-3049/com.example.spidey.jsontosql E/AndroidRuntime:     at dalvik.system.NativeStart.main(Native Method) 
    11-01 21:30:25.020 3049-3049/com.example.spidey.jsontosql I/Process: Sending signal. PID: 3049 SIG: 9</p>
  </blockquote>
  
  <p>I try to input data using my addStudent method but the program crashed.  Is there something wrong in my code?  Please help me to correct..</p>