我有java类适配器,这是错误的(Groceries b:getData()),因为对象无法转换为Groceries.java,如果我改为(Object b:的getData())我不能从Groceries.java调用一个方法b.getProduct()getSn()错误:不兼容的类型对象不能转换为(java类)
DataAdapter.java
public Groceries getBelBySN(String sn) {
Groceries pp = null;
for (Groceries b : getData()) {
if (b.getProduct().getSn().equals(sn)) {
pp = b;
break;
}
}
return pp;
}
public void updateTotal() {
long jumlah = 0;
for (Groceries b : getData()) {
jumlah = jumlah + (b.getProduct().getHarga() * b.getQuantity());
}
total = jumlah;
}
这是Groceries.java,我请适配器。
public class Groceries {
protected Product product;
protected int quantity;
public Groceries(Product product, int quantity) {
this.product = product;
this.quantity = quantity;
}
public void setProduct(Product product) {
this.product = product;
}
public Product getProduct() {
return product;
}
public void setQuantity(int quantity) {
this.quantity = quantity;
}
public int getQuantity() {
return quantity;
}
getData()返回什么?你能告诉我们'getData()'的代码吗? –
getData()是从列表 – Rizal