vlad wrote:
Code:
subjNames.add((Subject) list);
This doesn't look right and that's why you get the Exception.
If you had a List<Subject>, you'd call:
Code:
subjNames.addAll(list)
If you had a Subject instance, you'd call:
Code:
subjNames.add(subject)
Hi vliad,
I would like to clarify the above.
So, now I am using a constructor in my Subject class with a field variable String subject.
Therefore, in my Tutor class, I can't write this below as per your example right ?
public List<Subject>getSubjects(){
return subjNames;
}
public void addSubject(Subject subject){
subjNames.addAll(subjNames);
//subjNames.add((Subject) list);
((Subject) subjNames).setTutor(this);
//((Subject) list).setTutors(this);
}
public void removeSubject(Subject subject){
subjNames.remove(subject);
subject.setTutor(null);
}
cos with the above code, I am getting a java.lang.NullPointerException
at model.Tutor.addSubject(Tutor.java:184)
at controller.tutorController.doPost(tutorController.java:75)
In this case how should I write the add and remove portion ?