我有一个班级:
public class TypeOfCompressDTO {
private int typeOfCompressId;
private String typeOfCompress;
public TypeOfCompressDTO() {
}
public TypeOfCompressDTO(int typeOfCompressId, String typeOfCompress) {
this.typeOfCompressId = typeOfCompressId;
this.typeOfCompress = typeOfCompress;
}
public int getTypeOfCompressId() {
return typeOfCompressId;
}
public void setTypeOfCompressId(int typeOfCompressId) {
this.typeOfCompressId = typeOfCompressId;
}
public String getTypeOfCompress() {
return typeOfCompress;
}
public void setTypeOfCompress(String typeOfCompress) {
this.typeOfCompress = typeOfCompress;
}
}
和
@SuppressWarnings("serial")
public class FmCompressComposer extends BaseCustomComposer<FmCompressService, FmCompressDTO>{
Window wdwFmCompress;
//public ListModelList<TypeOfCompressDTO> listTypeOfProcess = new ListModelList();
List<TypeOfCompressDTO> lstTypeOfCompress = new ArrayList<TypeOfCompressDTO>();
TypeOfCompressDTO assssa = new TypeOfCompressDTO(3, "abc");
lstTypeOfCompress.add(assssa);
TypeOfCompressDTO g = new TypeOfCompressDTO(23, "axbc");
// public ListModel<TypeOfCompress> getListTypeOfProcess() {
// return listTypeOfProcess;
// }
@Override
protected Logger getLogger() {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
protected Window getWindow() {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
protected Listbox getGridData() {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
protected String getArgDTOKey() {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
protected void buildSearchObject() {
throw new UnsupportedOperationException("Not supported yet.");
}
}
在这一行:
lstTypeOfCompress.add(assssa);
在课程FmCompressComposer
中,Netbeans 7.x注意到:
包lstTypeOfCompress不存在 预期
预期
(Alt-Enter显示提示)
我不明白发生了什么,看起来很奇怪。请解释并帮助我纠正上述代码段。
答案 0 :(得分:3)
lstTypeOfCompress.add(assssa);
这是一个陈述/表达。它应该在一个方法/构造函数中。您只能声明成员并初始化它们。但是你正在进行操作,这是不允许的。
通过查看你的代码,我认为你应该定义一个构造函数来初始化类的成员,你也可以在列表中添加数据。