문자열 배열에 대해 java.lang.NullPointerException이 표시되는 이유를 정확히 모르시겠습니까? 나는 몇 시간 동안 찾았지만 문제를 찾을 수 없습니다. 여기 문자열 배열에 대해 java.lang.NullPointerException이 나타나는 이유는 무엇입니까?
private String[] stringList;
int j = 0;
StringClass stringRef = new StringClass();
while (//As long as there is string available from what I am reading in)
{
str = //String read in;
stringRef.setString(str);
stringList[j] = stringRef.returnString(); //Shows that this line is the error
j++;
}
클래스입니다 도와주세요 : 그것은 당신의 변수
stringList
의 이름에도 불구하고
public class StringClass {
private String stringNew;
public void setString(String newStr){
stringNew = newStr;
}
public String returnString(){
return stringNew;
}
}
당신이'공용 클래스 StringClass {...}를'찾으 셨나요? 여기
내 제안 된 변경 코드인가? 어느 쪽이든, 나는 그것이 당신이 당신의 학급에 이름을 지은 방법이 아니기를 바랍니다! – mystarrocks
그리고'stringList'는 예외를 던지는 시점에서'null'이됩니다. – mystarrocks