Grade Book class, please help
I have to do a multiclass program and there's a logic error that I can't figure out.
public void inputStudents() throws FileNotFoundException //This will work to interactively input Students
{
Scanner inF = new Scanner(new File("C:\\Users\\Caili\\Documents\\Sophmore\\AP Computer Science\\Unit 4\\TextFile.txt"));
while(inF.hasNextLine( ))
{
Student aStudent = new Student();
aStudent.inputInfo("Name",inF.nextLine( ));
aStudent.inputInfo("Tests",inF.nextLine( ));
aStudent.inputInfo("Programs",inF.nextLine( ));
aStudent.inputInfo("Homework",inF.nextLine( ));
aStudent.computeAve();
aStudent.computeGrade();
myStudents.add(aStudent); It says that this line is null when I try to run it.
}
I have this that goes along with the method
public void inputInfo(String scoresType,String info)
{
if(scoresType.equals("Name"))
myName = info;
else if(scoresType.equals("Tests"))
myTests.getScores(info);
else if(scoresType.equals("Programs"))
myProgs.getScores(info);
else if(scoresType.equals("Homework"))
myHk.getScores(info);
}
public void getScores(String lineNumbers) //Interactively read scores from the keyboard into an array (-999 terminates input)
{
Scanner lineScan = new Scanner(lineNumbers);
while(lineScan.hasNext())
{
int num = lineScan.nextInt();
myScores[mySize] = num;
mySize++;
}
}
Re: Grade Book class, please help
Does the variable myStudents have a valid value or is its value null?
Where do you define it and where do you give it a value?
Re: Grade Book class, please help
I declare it in the constucter
public ClassList()
{
ArrayList<Student> myStudents = new ArrayList<Student>();
int[] myGradeDistribution = new int[GREATEST_SIZE];
count = 0;
scoreSum = 0;
additional = 0;
}
Re: Grade Book class, please help
Quote:
myStudents.add(aStudent); It says that this line is null
Please post the full text of the error message. Your edited version is leaving off valuable information.
Re: Grade Book class, please help
in the Classlist class it says :java.lang.NullPointerException: null
Re: Grade Book class, please help
Please post the FULL text of the error message. Your edited version is leaving off important information.