我为学生制作方法,向每个学生展示我的GUI,我希望有选项将我的GUi保存到xml文件中。我的问题是我有错误空指针异常
我解决了写作学生的问题
我制作私人综合mSTUDENTChild
;
我每写studentChild = mSTUDENTChild;
并写入保存部分我做
Control[] currentSTUDENTOnGui = mSTUDENTChild.getChildren();
我的问题是写出我有的主题
public void displaySTUDENTTab(TabFolder tabFolderAdministration, CurrentData currentData){
TabItem tbtmSTUDENT = new TabItem(tabFolderAdministration, SWT.NONE);
tbtmSTUDENT.setText("STUDENT");
ScrolledComposite scrolledComposite_7 = new ScrolledComposite(tabFolderAdministration, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
tbtmSTUDENT.setControl(scrolledComposite_7);
scrolledComposite_7.setExpandHorizontal(true);
scrolledComposite_7.setExpandVertical(true);
List<STUDENT> allStudentNodes = currentData.getstudentNodes();
final Composite studentChild = new Composite(scrolledComposite_7, SWT.NONE);
studentChild.setLayout(new GridLayout());
for(STUDENT studentNode: allStudentNodes){
new studentNode(this, studentChild, SWT.NONE, studentNode);
Composite subjectChild = new Composite(studentChild, SWT.NONE);
GridLayout bladeGrid = new GridLayout(9, true);
subjectChild.setLayout(bladeGrid);
for(Blade bladeNode: studentNode.getBlades()){
new BladeID(subjectChild, SWT.NONE, bladeNode);
}
msubjectChild = subjectChild;
}
mstudentChild = studentChild;
scrolledComposite_7.setContent(studentChild);
scrolledComposite_7.setMinSize(studentChild.computeSize(SWT.DEFAULT, SWT.DEFAULT));
scrolledComposite_7.pack();
}
我制作了saveas方法,现在正在使用这是我保存的代码,我有课程SUBJECT
,SUBJECTID
和AddSubject
Control[] currentSTUDENTOnGui = studentChild.getChildren();
int noOfBCs = -1;
currentData.getStudentNodes().clear();
for (int i = 0; i < currentSTUDENTOnGui.length; i++) {
boolean isBCNode = false;
SubjectNode subjectOnGuii = null;
STUDENTNode nodeOnGuiSTUDENT = null;
try {
nodeOnGuiSTUDENT = (STUDENTNode) currentSTUDENTOnGui[i];
isBCNode = true;
noOfBCs++;
} catch (ClassCastException e) {
subjectOnGuii = (SubjectNode) currentSTUDENTOnGui[i];
}
if (isBCNode) {
STUDENT nodeWithDataSTUDENT = new STUDENT(nodeOnGuiSTUDENT.getText(), nodeOnGuiSTUDENT.getText_1(), nodeOnGuiSTUDENT.getText_2(), nodeOnGuiSTUDENT.getText_3(),
nodeOnGuiSTUDENT.getText_4(), nodeOnGuiSTUDENT.getText_5(), nodeOnGuiSTUDENT.getText_6(), nodeOnGuiSTUDENT.getText_7(), nodeOnGuiSTUDENT.getText_8(), nodeOnGuiSTUDENT.getText_9(), nodeOnGuiSTUDENT.getText_10(),
nodeOnGuiSTUDENT.getText_11(), nodeOnGuiSTUDENT.getText_12(), nodeOnGuiSTUDENT.getText_13(), nodeOnGuiSTUDENT.getText_14(), nodeOnGuiSTUDENT.getText_15(), nodeOnGuiSTUDENT.getText_16());
currentData.getStudentNodes().add(nodeWithDataSTUDENT);
continue;
}
STUDENT lastNodeWithData = currentData.getStudentNodes().get(noOfBCs);
SUBJECT subjectToAdd = new SUBJECT(subjectOnGuii.getId(), subjectOnGuii.getSessionType(), subjectOnGuii.getUser(), subjectOnGuii.getSupwd(), subjectOnGuii.getPort());
lastNodeWithData.getSubject().add(subjectToAdd);
currentData.getStudentNodes().set(noOfBCs, lastNodeWithData);
}