Hi Guys I am new to Java Why does it throws null pointer exception?? My Customer Class
package com.syncfusion;
import java.util.List;
public class Customers {
private List<String> customerNamesList;
public void addCustomerName(String customerName) {
customerNamesList.add(customerName);
System.out.println(customerName);
}
public void printAllCustomers() {
for(String customer : customerNamesList) {
System.out.println(customer);
}
}
}
and my Main function is as shown below:
package com.syncfusion;
public class Persons {
public static void main(String[] args) {
Customers customer = new Customers();
customer.addCustomerName("Inteflex Inc");
}
}
Why does it throw null pointer ? and I hope i have instanciated the Customer Class but it has error