Can';不要在其他类中使用构造函数Android(Java)
我试图创建一个列表视图,每个列表元素有3个文本视图 以下是MainActivity.java中声明的值Can';不要在其他类中使用构造函数Android(Java),java,android,Java,Android,我试图创建一个列表视图,每个列表元素有3个文本视图 以下是MainActivity.java中声明的值 ListView listView; ArrayAdapter<String> arrayAdapter; ArrayList<String> arrayList; 错误是 dataList.add((新骑乘(日期[i],时间[i],距离[i])); 我的元素类非常简单,是一个构造函数和getter: public class Element { priva
ListView listView;
ArrayAdapter<String> arrayAdapter;
ArrayList<String> arrayList;
错误是
dataList.add((新骑乘(日期[i],时间[i],距离[i]));
我的元素类非常简单,是一个构造函数和getter:
public class Element {
private String fire;
private String earth;
private String water;
public Element(String fire, String earth, String water) {
this.fire = fire;
this.earth = earth;
this.water = water;
}
public String getFire() {
return this.fire;
}
public String getEarth() {
return this.Earth;
}
public String getWater() {
return this.Water;
}
}
什么可能导致此问题?ArrayList
读取为String
类型对象的列表。所以很可能ArrayList
就是你想要的
ArrayList<Element> arrayList;
这就是为什么在String
s列表中尝试添加Element
类型的objects()时会出现错误
此外,您的构造函数必须与类名匹配,因此将其更改为Element()
您的问题是什么?包括您在post公共设施中收到的错误(串火、串土、串水)
这看起来像一个构造函数(没有返回类型),但它的名称与类名不匹配(元素
)。
public class Element {
private String fire;
private String earth;
private String water;
public Element(String fire, String earth, String water) {
this.fire = fire;
this.earth = earth;
this.water = water;
}
public String getFire() {
return this.fire;
}
public String getEarth() {
return this.Earth;
}
public String getWater() {
return this.Water;
}
}
ArrayList<Element> arrayList;
public class Element {
private String fire;
private String earth;
private String water;
public Element(String fire, String earth, String water) {
this.fire = fire;
this.earth = earth;
this.water = water;
}
public String getFire() {
return this.fire;
}
public String getEarth() {
return this.Earth;
}
public String getWater() {
return this.Water;
}
}