So im writing a Java programming, I have 2 classes, and a class test that uses these 2 classes. running eclipseIDE, it keeps telling me i have a NullPointerException at the "s+=c.getName() + " " +... "
this is a method in Student.
public String getCourses()
{
String s = "";
for(Course c: this.courses)
{
s+=c.getName() + " " + c.getID() + " " + c.getScore(this.id);
s+="\n";
}
return s;
}
it calls this method that is in the Course class.
public String getID()
{
return this.id;
}
i tried only doing getName(); it had no issue, however once i added getID() it became an issue. getName is the same type of code, it returns the "name" of the object as a string.
name and id is "initialized" via a constructor
Stacktrace:
Exception in thread "main" java.lang.NullPointerException
at hw6.Student.getCourses(Student.java:47)
at hw6.CourseStudent_test.main(CourseStudent_test.java:100)
this is the getScore method
public double getScore(String id)
{
int i = 0;
for(; i < this.students.length;i++)
{
if(this.students[i].getID() == id )
{
break;
}
}
return this.scores[i];
}