Good day. I suffer for several hours. There is a Load class:

public class Load { protected String teacher; protected int groupe; protected int numberOfHourses; protected String subject; protected String typeOfEmployment; protected int payment; public Load(){ } public Load(String teacher, int groupe, int numberOfHourses, String subject, String typeOfEmployment, int payment) { this.teacher = teacher; this.groupe = groupe; this.numberOfHourses = numberOfHourses; this.subject = subject; this.typeOfEmployment = typeOfEmployment; this.payment = payment; } public String get(){ return( this.teacher + ' ' + this.groupe + ' ' + this.numberOfHourses + ' ' + this.subject + ' ' + this.typeOfEmployment + ' ' + this.payment); } } 

And there is also a Loads class:

 public class Loads { public List<Load> loadsList = new LinkedList<>(); // Расчёт оплаты private int payment(String subject, String typeOfEmployment){ int subj = 0; int tOE = 0; if ((subject.compareTo("English")) == 0) subj = 2; else if ((subject.compareTo("BigData")) == 0) subj = 3; else if ((subject.compareTo("OS")) == 0) subj = 2; else if ((subject.compareTo("OOP")) == 0) subj = 2; if ((typeOfEmployment.compareTo("Lecture")) == 0) tOE = 2; else if ((typeOfEmployment.compareTo("Practice")) == 0) tOE = 3; return (2*(subj+tOE)); } // Заполнение коллекции public void addLoad(){ Teachers teachersL = new Teachers(); Groups groups = new Groups(); ListIterator<Teacher> itr = teachersL.teachersList.listIterator(); if (itr.hasNext()){ Load load1 = new Load(teachersL.teachersList.get(0).getName(), groups.groupsList.get(0).number, 2, "English", "Lecture", payment("English", "Lecture")); Load load2 = new Load(teachersL.teachersList.get(1).getName(), groups.groupsList.get(1).number, 2, "BigData", "Lecture", payment("BigData", "Lecture")); Load load3 = new Load(teachersL.teachersList.get(2).getName(), groups.groupsList.get(1).number, 3, "OS", "Practice", payment("OS", "Practice")); Load load4 = new Load(teachersL.teachersList.get(3).getName(), groups.groupsList.get(2).number, 2, "OOP", "Lecture", payment("OOP", "Lecture")); Load load5 = new Load(teachersL.teachersList.get(4).getName(), groups.groupsList.get(3).number, 3, "OS", "Lecture", payment("OS", "Lecture")); Load load6 = new Load(teachersL.teachersList.get(5).getName(), groups.groupsList.get(1).number, 3, "BigData", "Practice", payment("BigData", "Practice")); loadsList.add(load1); loadsList.add(load2); loadsList.add(load3); loadsList.add(load4); loadsList.add(load5); loadsList.add(load6); } } } 

In the Loads class, the linkedlist collection must be populated with Load objects. In the other two classes, the filling works, everything is as it is written to the file and read. But here even the collection is not filled (checked through size(); ). How to be?

  • Go through the code under the debugger, look at the variables, it's hard to say, it looks all right. - Ep1demic
  • check iterator - Pollux
  • Apparently, you just created teachersL . Those. It is in fact "empty." Where does the data for busting come from? - Chubatiy
  • @Chubatiy, In main`e, I first call the WriteT method, it calls the method from Teachers, which fills the collection in the Teachers class. Then I call the writeL method, in which the loadsList is filled. But writeT uses the instance name of the teachers. Because of this? - alex.stepan
  • Everything solved the problem. Chubatiy brought me to the idea of ​​checking the results when the names match (calling the teachers from the main class instead of creating teachersL). Thank you for your help. - alex.stepan

0