這是我收到的錯誤,當我嘗試運行我的代碼下面。我的老師說我們可以在任何地方尋求幫助。我將不勝感激,如果有人可以幫助我這個錯誤java錯誤消息空指針異常
java.lang.NullPointerException
at Practise_Assessment.main(Practise_Assessment.java:35)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at edu.rice.cs.drjava.model.compiler.JavacCompiler.runCommand(JavacCompiler.java:272)
這裏是我的代碼,如果需要的話
import java.text.NumberFormat;
import java.util.Arrays;
public class Practise_Assessment {
public static String absences(String prompt) {// user input for name and
// days absent
System.out.println(prompt);
java.util.Scanner keyboard = new java.util.Scanner(System.in);
return keyboard.nextLine();
}
public static void main(String[] args) throws Exception {
int numDayEntries ;
int numNameEntries;
int[] daysArray = null ;
String[] nameArray = null ;
boolean done = false;
while (!done) {
System.out.println("enter # to stop");
String absences = absences("enter name of person absent then the amount of days they were absent");// the value of the users input
for(numDayEntries =0; numDayEntries < daysArray.length;numDayEntries++){
daysArray = new int[numDayEntries];
}
for(numNameEntries = 0; numNameEntries < nameArray.length;numNameEntries++){
nameArray = new String[numNameEntries];
}
if (absences.equalsIgnoreCase("#")) {
done = true;
} else {
String DaysAbsent =absences.replaceAll("[^0-9]", "") ;
int daysAbsent = ((Number) NumberFormat.getInstance().parse(DaysAbsent)).intValue();// converts a string to an int
String absentee = absences.replaceAll("\\d", "");// replace all digits in the user input to nothing leaving just the name
daysArray[numDayEntries] = daysAbsent;
nameArray[numNameEntries] = absentee;
}
}
System.out.println(Arrays.toString(daysArray));
}
}
Daysarray變量爲空 – fmodos
感謝大家誰回覆,你們(和女孩)幫助這麼多 – user3023714
@ user3023714然後,你應該接受幫助你解決它的答案。 – Keerthivasan