我有对象的列表中某些类的数组列表:如何从其他类访问列表中的对象?
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", "[email protected]","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方法返回列表<客户>现在,但问题仍然在这里。
你的“数据”是私人的,你不能在你的班级以外的地方访问它,除非你实现了getter和setter ......无论如何,你的班级的设计似乎有点搞砸 –
你可能忘记在末尾加上分号行'list.get(0).data [0] =“999”'? –
已将其更改为公开,但未使错误消失。分号也不是问题。当我写信时,intelliJ甚至不接受“get”list.get(0) –