Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy am I getting null on this code?
    primarykey
    data
    text
    <p>This is a part of my source (when I enter a button) of my JDilog form. I have made an object from the <code>SystemManagement</code> class which is management (I have written also some part of this class). When the user add her/his information, with the <code>addStudent()</code> method in <code>SystemManagement</code> class I add her/his information to the student's list but when I write </p> <pre><code>System.out.println(management.getField()); </code></pre> <p>It will return null! Why?</p> <pre><code> private void submit() { String name = nameField.getText(); String family = familyField.getText(); String ye = (String) yearComboBox.getSelectedItem(); String ci = (String) cityComboBox.getSelectedItem(); String fi = (String) fieldComboBox.getSelectedItem(); if (ye == null) { JOptionPane.showMessageDialog(this, "You haven't chosen the year of entrance", "Error", JOptionPane.ERROR_MESSAGE); return; } if (ci == null) { JOptionPane.showMessageDialog(this, "You have not set the city", "Error", JOptionPane.ERROR_MESSAGE); return; } if (fi == null) { JOptionPane.showMessageDialog(this, " You have not set the field", "Error", JOptionPane.ERROR_MESSAGE); return; } if (name.equals("")) { JOptionPane.showMessageDialog(this, "You have not set your name ", "Error", JOptionPane.ERROR_MESSAGE); return; } if (family.equals("")) { JOptionPane.showMessageDialog(this, " You have not set the family", "Error ", JOptionPane.ERROR_MESSAGE); return; } management.addStudent(name, family, ye,ci, fi); System.out.println(management.getField()); JOptionPane.showMessageDialog(this, management.toString(), " registered successefully", JOptionPane.INFORMATION_MESSAGE); clear(); } public class SystemManagement implements Serializable { private String siteName; private List&lt;Fields&gt; fields; private List&lt;Professors&gt; professors; private List&lt;Students&gt; students; private List&lt;Lessons&gt; lessons; public Professors pro; public Lessons les; public SystemManagement(String siteName) { this.siteName = siteName; professors = new ArrayList&lt;Professors&gt;(); students = new ArrayList&lt;Students&gt;(); lessons = new ArrayList&lt;Lessons&gt;(); fields = new ArrayList&lt;Fields&gt;(); } public List&lt;Fields&gt; getFields() { return fields; } public void setField(String field) { this.field = field; } public String getField() { return field; } public void addStudent(String name, String family, String yearOfEntrance, String city, String field) { Students student = new Students(name, family, yearOfEntrance, city, field); students.add(student); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload