Hello there,
I'm working on a project and for this I'm using classes, in my main I'm using an array of objects. When I compile it, it works fine, but when I try to enter values, it displays this message:
"Exception in thread "main" java.lang.NullPointerException
at main.main(main.java:25)"
Here is my code:
public class Customer {
public Customer (String theName, int theAge, int theID)
{
name = theName;
age = theAge;
ID = theID;
}
public void setName(String theName)
{
name = theName;
}
public void setAge(int theAge)
{
age = theAge;
}
public void setID(int theID)
{
ID = theID;
}
public String getName()
{
return name;
}
public int getAge()
{
return age;
}
public int getID()
{
return ID;
}
public String name;
public int age;
public int ID;
}
- customers.java
import java.util.Scanner;
public class main {
public static void main(String args[])
{
int menue_choice = 0;
int i=0;
String inputtedName;
Customer customers[] = new Customer[500];
Seat seats[] = new Seat[328];
Scanner in = new Scanner(System.in);
System.out.println("Welcome. Please select from the following options:");
System.out.println("\n\t\t1. Add Customer\n\t\t2. Book a seat\n\t\t3. Quit");
menue_choice = in.nextInt();
switch(menue_choice)
{
case 1:
String inputted_name;
int inputted_age;
customers[1].setName("Phillip");
System.out.println(customers[1].getName());
break;
case 2:
break;
case 3:
break;
case 4:
break;
default:
break;
}
}
}
Any ideas? Thanks =)