도움을 미리 감사드립니다.개체에 대한 NullPointerException
public Question(String text) {
this.totalPossibleSelections = 1;
this.text = text;
this.currentSelections = new QuestionElement[1];
this.finalSelections = new QuestionElement[1];
}
와 같은 클래스에서이 방법 :
나는 다음과 같은 생성자가
protected QuestionElement[] currentSelections;
내 객체 Question
의 매개 변수 중 하나입니다
public void setCurrentSelection(QuestionElement selection) {
if (totalPossibleSelections == 1){
currentSelections[0] = selection;
}
}
.
currentSelections
은 NullPointerException
을 유발하는 setCurrentSelection
으로 전화하면 null
입니다. 메서드 setCurrentSelection
은 질문에만 작동 할 수 있으므로 currentSelections
은 null이 아니어야합니다. 다른 코드에서 생성자를 호출하여 내 Question
을 초기화했습니다. 여기에 무슨 일이 벌어지고 있을까요?
편집 : Question
의 하위 클래스가 없습니다. 또한 생성자가 호출됩니다. 그렇지 않은 경우 totalPossibleSelections
은 null
이됩니다.
null 일 수 없습니다 혼란 다음을 방지하기 위해'클래스에서 다른 곳 currentSelections'. – Eran
U가 배열을 초기화하고 디버그 모드를 실행하는 중단 점을 설정합니다. –
상속 있습니까? currentSelections가 기본 클래스의 일부인지, 아니면 "내 객체의 매개 변수 질문"을 의미합니까? 또 다른 생성자? –