db4o数据库存放的class含有相同的字段名且字段的类型也相同。现在想把这个库中数据读出来,但总是报 java.lang.ClassCastException错误,请大侠指教
具体情况如下:
ObjectContainer db =null;
try {
db = Db4o.openFile("bean.yap");
List<AlarmFilter> list_a = db.get(AlarmFilter.class);
for(int x = 0; x < list_a.size(); x++)
System.out.println(list_a.get(x).toString());
}finally {
// 关闭连接
if(db!=null)
db.close();
}
AlarmFilter存储类的定义:
public class AlarmFilter {
public AlarmFilter() {
// TODO Auto-generated constructor stub
}
public String toString(){
return "["+this.positive+this.name+this.description+"]";
}
private boolean positive; //是否生效
private List<FilterItemImpl> itemList;//一个条件的内容
private String name;//一条规则中一个条件的名称
private String description;//描述,扩展项
private String filterId;//条件ID,扩展项
private String creator;//创建用户,扩展项
private String isActive;//是否启用,扩展项
public boolean isPositive() { return positive; }
public void setPositive(boolean positive) {
this.positive = positive;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getFilterId() {
return filterId;
}
public void setFilterId(String filterId) {
this.filterId = filterId;
}
public String getCreator() {
return creator;
}
public void setCreator(String creator) {
this.creator = creator;
}
public String getIsActive() {
return isActive;
}
public void setIsActive(String isActive) {
this.isActive = isActive;
}
public List<FilterItemImpl> getItemList() {
return this.itemList;
}
public void addItemList(FilterItemImpl filterItemImpl) {
if(null==this.itemList)
itemList=new ArrayList<FilterItemImpl>();
this.itemList.add(filterItemImpl);
}
}