Monday, 15 August 2011

error handling - java.lang.NullPointerexception in java -


When I set up the interface using topic.getSubjectHasProgram () I am getting NullPointerException. But subject.getSubjectHasProgram () Show the size () equal to 2 which is what I want .. !!

  set & lt; Subject & gt; Sub = (set & topic; topic & gt;) this.teacher.getSubjects (); (Iterator & Lt; subject & gt; Iterator = sub .iterator (); iterator.hasNext ();) {subject next = (theme) iterator.next (); If (next.getID () == this.ID) {this.Name = next.getName (); System.out.println ("Subject name =" + this.Name); This.CourseCode = next.getCourseCode (); This.CreditHour = next.getCreditHour (); ** System.out.println ("programscount =" + next.getSubjectHasPrograms (). Size ()); ** for (iterator2 = next .getSubjectHasPrograms (). Iterator (); iterator2.hasNext ();) {ProgramHasSubject ProgramHasSubject = (Program HasSubject) iterator2.next (); This.selectedPrograms.add (programHasSubject.getProgram_ID ()); System.out.println ("Program ID:" + programHasSubject.getProgram_ID (). GetID ()); System.out.println ("Program Name:" + Program HasSubject.getProgram_ID (.) GetName ()); System.out.println ("semester:" + program HasSubject.getSemester_ID ()); }            break; }}  

You actually have two statements for the loop.

Iterator Iterator 2 = Next .get Thematic Program (). Iterator (); And iterator2.hasNext ();

Did you verify that next.getSubjectHasPrograms () Iterator (); a null not back


No comments:

Post a Comment