I'm quite stumped on my situation here. I'm really not sure why I'm getting this null pointer exception.
//here is a method from one of my classes
public class UI {
Registry reg;
public UI (Registry reg) {
this.reg = reg;
menu();
}
private void addAppts(Scanner sc) {
System.out.println("Enter the month for appointment in mm/dd/yyyy format:");
sc.nextLine();
int month = sc.nextInt();
System.out.println("Enter the day for appointment mm/dd/yyyy format:");
sc.nextLine();
int day = sc.nextInt();
System.out.println("Enter the year for appointment mm/dd/yyyy format:");
sc.nextLine();
int year = sc.nextInt();
System.out.println("Enter the hour for appointment:");
sc.nextLine();
int hour = sc.nextInt();
System.out.println("Enter the minute for appointment:");
sc.nextLine();
int minute = sc.nextInt();
System.out.println("Enter the owner name for appointment:");
sc.nextLine();
String ownerName = sc.nextLine();
reg.addAppts(month, day, year, hour, minute, ownerName);
}
}
//and here is another method from my other class
public class Registry {
private Appointments[] appts;
public void addAppts(int month, int day, int year, int hour, int minute, String ownerName) {
if (next < appts.length) {
Appointments e = new Appointments(month, day, year, hour, minute, ownerName);
appts[next++] = e;
}
}
}
public class Appointments {
private int month, day, year, hour, minute;
private String ownerName;
public Appointments(int month, int day, int year, int hour, int minute, String ownerName) {
this.month = month;
this.day = day;
this.year = year;
this.hour = hour;
this.minute = minute;
this.ownerName = ownerName;
}
}
I'm getting the nullpointer exception error on the last line of the first method. Any suggestions?
regdefined? is it initialized?UIget instansiated?appts, i think that might be an issue if this is complete code