【发布时间】:2019-04-18 13:34:35
【问题描述】:
我有 items 类,其中包含 mProductType 等字段。
在这个类里面有如下方法:
public ArrayList<Item> getProductsByCategory(String category, ArrayList<Item> productList) {
ArrayList<Item> returnList = new ArrayList<>();
for (int i = 0; i < productList.size(); i++) {
if (productList.get(i).getmProductType() == category) {
returnList.add(productList.get(i));
}
}
return returnList;
}
到目前为止一切顺利。在我的另一个类ProductsInCategoryFragment 中,我尝试调用这样的方法:
ArrayList<Item> products;
// ... filling variable "products" with content
products = fetcher.getItems();
// ... declaring the category String
String category = getArguments().getString("CATEGORY");
products.getProductsByCategory(category, products);
我可以从类项的实例调用该方法,但不能在该类的 ArrayList 上调用。最后一行代码给了我这个错误:
Error:(82, 17) error: cannot find symbol method getProductsByCategory(String,ArrayList<Item>)
我知道这可能是一个非常基本的问题,但我似乎无法掌握它。这是某种可见性问题吗?
【问题讨论】: