Exception in thread "main" java.lang.NullPointerException
I am new to java. And I am keeping receiving this error message. I don't know why this is happening
Code:
import java.util.*;
import javax.swing.*;
/**
*
* @author Administrator
*/
public class CarRegistation {
private ArrayList CarOwner = null;
private ArrayList CarRegInfo = null;
public void CarRegistation(){
CarOwner = new ArrayList();
CarRegInfo = new ArrayList();
}
public void newCarRegistation(String oc, String nic, String man, String Reg){
//try{
//PersonsInfo p = new PersonsInfo(oc, nic);
PersonsInfo p = new PersonsInfo(oc, nic);
Cars c = new Cars(man, Reg);
CarOwner.add(p); //error comes here Null Pointer
CarRegInfo.add(c);
/*}catch (Exception e){
JOptionPane.showMessageDialog(null, e.getMessage());
}*/
}
public void searchCarRegistation (String n) {
// try{
for(int i=0; i<CarOwner.size(); i++){
PersonsInfo p = (PersonsInfo)CarOwner.get(i);
Cars c = (Cars)CarRegInfo.get(i);
if (n.equals(p.getName())){
// WindowsApplication wa = new WindowsApplication();
// wa.txtManufacturer.setText(c.getCarManufacturer());
// wa.txtOwnerOfCar.setText(p.getName());
// wa.txtNicNo.setText(p.getNicNo());
// wa.txtRegistationNo.setText(c.getRegistation());
}
}
/*}catch (Exception e){
JOptionPane.showConfirmDialog(null, e.getMessage());
}*/
}
public void deleteCarRegistation(String nic){
/*try{*/
for(int i=0; i<CarOwner.size(); i++){
PersonsInfo p = (PersonsInfo)CarOwner.get(i);
//Cars c = (Cars)CarRegInfo.get(i);
if (nic.equals(p.getNicNo())){
CarOwner.remove(i);
CarRegInfo.remove(i);
JOptionPane.showMessageDialog(null, "Car having NIC: " + p.getNicNo() + "has been remove from list");
}
}
//}catch (Exception e){
// JOptionPane.showConfirmDialog(null, e.getMessage());
//}
}
public int countCarRegistation(String n){
int size = 0;
//try{
for(int i=0; i<CarOwner.size();i++){
PersonsInfo p = (PersonsInfo)CarOwner.get(i);
if(n.equals(p.getName())){
size = size + 1;
}
}
//}
//catch (Exception e){
// JOptionPane.showConfirmDialog(null, e.getMessage());
// }
return size;
}
}
Please help me out as I have to submit this code ASAP. Thanks in advance.
Constructor doesnt have a return type