在课堂上设置/获取方法" hostel_DtRm " (日期和房间的缩写)。我说得很简单,所以你明白了。
public class hostel_DtRm {
private String guests;
// Constructor
public hostel_DtRm (){}
// Set guests method
public void setguests(String guests) {
this.guests=guests;
}
//get guest method
public String getguests() {
return guests;
}
另一个名为" LogedInMain "的类,其中来自" hostel_DtRm "的设置方法人口稠密。
public class LogedInMain {
private hostel_DtRm dtrm;
public LogedInMain(hostel_DtRm dtrm ) {
this.dtrm=dtrm;
initialize();
........
.....
填充集合并从" hostel_DtRm "获取方法来自" LogedInMain "的课程类
hostel_DtRm dtrm= new hostel_DtRm();
dtrm.setguests(guests.getText());
dtrm.setstartdate(((JTextField)checkin.getDateEditor().getUiComponent()).getText());
dtrm.setenddate(((JTextField)checkout.getDateEditor().getUiComponent()).getText());
" TEST "是我想要操纵所获取数据的类。
public class TEST {
private hostel_DtRm dtrm;
public TEST( hostel_DtRm dtrm) {
this.dtrm=dtrm;
initialize();
}
private void initialize() {
JLabel guest = new JLabel(dtrm.getguests());
guest.setForeground(Color.DARK_GRAY);
guest.setBounds(41, 141, 86, 27);
LogedInmain.add(guest);
我没有获取客人号码,而是在线程" AWT-EventQueue-0"中得到了一个漂亮的" 异常。显示java.lang.NullPointerException "
我做错了什么?