【发布时间】:2016-05-11 12:03:21
【问题描述】:
我在某个类的数组列表中有一个对象列表:
public class Customer implements barber.barberapp.crud {
private String[] data = {"id", "imie", "nazwisko", "email", "tel"};
public static List<Customer> getClients(){
List<Customer> list = new ArrayList<Customer>();
Customer c1 = new Customer("001", "Adam", "Nowak", "an@wp.pl","123");
list.add(c1);
list.get(0).data[0] = "999"; //checking if accessing object works correctly
return list;
}
}
现在,当我尝试像这样访问其他类中的列表时,我收到一个错误“无法解析符号获取”。
public class CustomerListActivity extends AppCompatActivity {
List<Customer> list = Customer.getClients();
list.get(0).data[0] = "999" //error here
}
编辑:getClients 方法现在返回 List
【问题讨论】:
-
您的“数据”是私有的,除非您实现 getter 和 setter,否则您无法在课堂外访问它......无论如何,您的课程设计似乎有点混乱
-
您是否忘记在
list.get(0).data[0] = "999"行尾添加分号? -
将其更改为公开,但并没有使错误消失。分号也不是问题。当我写 list.get(0) 时,intelliJ 甚至不接受“get”
-
你们能提供MCVE吗?包括进口。 stackoverflow.com/help/mcve