import java.io.*;
public class workPoS {
/**
* @param args
*/
public static void main(String[] args) {
dataList[] some_list = new dataList[10];
for (int x = 0; x < some_list.length; x++) {
some_list[x].firstName = "John";
some_list[x].middleName = "Jacob";
some_list[x].lastName = "Jingle-Heimer-Schmidt";
some_list[x].age = 101;
}
for (int x = 0; x < some_list.length; x++) {
System.out.println(some_list[x].firstName + " "
+ some_list[x].middleName + " " + some_list[x].lastName
+ " Age: " + some_list[x].age);
}
}
public class dataList {
String firstName, middleName, lastName;
int age;
public dataList() {
firstName = "";
middleName = "";
lastName = "";
age = 0;
}
}
}
ERROR: Exception in thread "main" java.lang.NullPointerException at workPoS.main(workPoS.java:12)
This is line 12:
some_list[x].firstName = "John";
It seems that I am able to access some_list[x], but as soon as I specify a constructor, some_list[x].firstName, the result is a null value.
Am I simply referencing the constructor value incorrectly? If so, what is the correct way to do so?
Thanks guys!
mainlike it is for a desktop application.