Need help correcting - Newbie don't know what's wrong
So, hello all. This is my first post btw xD Im a first year Computing student and I got suspended so I can't get any more help from my tutors.
But I still do exercises. This one is supposed to be easy but I'm completely lost.
I had to develop an application that would store, and then display contacts details from an array.
I got 2 classes for that. Here's the codes:
Code:
package addressBook;
public class Person {
String firstName;
String lastName;
String dob;
/**
* @param firstName
* @param lastName
* @param dob
*/
public Person(String firstName, String lastName, String dob) {
this.firstName = firstName;
this.lastName = lastName;
this.dob = dob;
}
/**
* @return the firstName
*/
public String getFirstName() {
return firstName;
}
/**
* @param firstName the firstName to set
*/
public void setFirstName(String firstName) {
this.firstName = firstName;
}
/**
* @return the lastName
*/
public String getLastName() {
return lastName;
}
/**
* @param lastName the lastName to set
*/
public void setLastName(String lastName) {
this.lastName = lastName;
}
/**
* @return the dob
*/
public String getDob() {
return dob;
}
/**
* @param dob the dob to set
*/
public void setDob(String dob) {
this.dob = dob;
}
}
and
Code:
package addressBook;
import javax.swing.JOptionPane;
public class AddressBook1 {
/**
* @param args
*/
public static void main(String[] args) {
Person [] contacts = new Person[10];
for (int i=0; i < 10; i++) {
contacts[i].firstName = JOptionPane.showInputDialog("Input first name");
contacts[i].lastName = JOptionPane.showInputDialog("Input last name");
contacts[i].dob = JOptionPane.showInputDialog("Input date of birth");
System.out.println(contacts[i].getFirstName());
System.out.println(contacts[i].getLastName());
System.out.println(contacts[i].getDob());
}
}
}
I'll be thankful for any explanation what did I do wrong, and... don't stone me right away xD
EDIT: Haha... right ...
So: It gets to the first entry point (Asking for the first name) and then gives:
Code:
Exception in thread "main" java.lang.NullPointerException
at addressBook.AddressBook1.main(AddressBook1.java:13)