저는 여기 상황이 아주 어려워요. 왜이 null 포인터 예외가 발생하는지 잘 모르겠습니다. 여기 내 클래스 중 하나의 방법입니다 //자바에서 사용자가 입력 한 후 NullPointerException이 발생했습니다.
는
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);
}
}
// 여기가
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;
}
}
나는에 nullpointer 예외 오류를 받고 있어요 내 다른 클래스에서 다른 방법 첫 번째 방법의 마지막 줄. 제안 사항이 있으십니까?
여기서 'reg'는 정의되어 있습니까? 그것은 초기화 되었습니까? – sanbhat
'UI'는 어떻게 시작됩니까? – epoch
우리에게 스택 추적을 보여주고, 어디에서'appts'를 시작했는지, 이것이 완전한 코드라면 문제가 될 것이라고 생각합니다. – user902383