这是我在下面运行我的代码时收到的错误。我的老师说我们可以在任何地方寻求帮助。如果有人能帮助我解决这个错误,我将非常感激
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));
}
}