這是我的源代碼(當我輸入按鈕時)我的JDilog表單的一部分。我從SystemManagement
這個管理類(我也寫過這個類的一部分)中提出了一個對象。當用戶在SystemManagement
類添加他/她的信息,與addStudent()
方法我她/他的信息添加到學生的名單,但是當我寫爲什麼我在這段代碼上變爲null?
System.out.println(management.getField());
它將返回null!爲什麼?
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<Fields> fields;
private List<Professors> professors;
private List<Students> students;
private List<Lessons> lessons;
public Professors pro;
public Lessons les;
public SystemManagement(String siteName) {
this.siteName = siteName;
professors = new ArrayList<Professors>();
students = new ArrayList<Students>();
lessons = new ArrayList<Lessons>();
fields = new ArrayList<Fields>();
}
public List<Fields> 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);
}
很難說不知道這個管理類,特別是getField()方法是如何實現的,或者實際返回的是什麼。請優化您的問題並提供一些課程代碼。 – Olli 2009-11-20 11:49:26
另外,這個問題與標題無關? – Olli 2009-11-20 11:50:18
標題應該更加具體 – 2009-11-20 12:46:41