我想将图像和文本组加载到列表中的项目,因此每个项目在viewpager中都有3个文本视图和图像组,所以我让java类包含获取和设置文本和图像的方法url,这是我的代码
更新我解决了以前的问题,但是当将字符串数组发送到项目类时,它会给出红色下划线错误
public class Projects {
private String yourText = "";
private String yourstatu= "";
private String yourdes= "";
private String yourversion= "";
private String[] img;
public String getyourText () {
return yourText ;
}
public void setyourText(String yourText) {
this.yourText = yourText;
}
public String getyourdescription () {
return yourdes ;
}
public void setyourdescription( String yourdes) {
this.yourdes = yourdes;
}
public String getyourstatu () {
return yourstatu ;
}
public void setyourstatu( String yourstatu) {
this.yourstatu = yourstatu;
}
public String getYourversion() {
return yourversion ;
}
public void setYourversion( String yourversion) {
this.yourversion = yourversion;
}
public String getYourimages() {
return new String[] img ; // here red underline
}
public void setYourimages( String []img) {
this.img = img;
}
} 我的主页的一部分
mProduct.setyourText(name11);
mProduct.setyourstatu(status);
mProduct.setYourversion(version);
mProduct.setyourdescription(description);
mArrayList.add(mProduct);
for (int i = 0; i < jreimages.length(); i++) {
JSONObject jjobject = jreimages.getJSONObject(i);
String imageid=jjobject.getString("project_id");
if(imageid==id){
String urlimage=jjobject.getString("screenshot");
String total=url+urlimage;
images[j]=total;
}
mProduct.getYourimages(images); // here underline error says getYourimages cannot be applied to java.lang,string[]
如何返回字符串数组?
答案 0 :(得分:1)
你定义了一个Strings - String [] img数组,所以你可以从你的函数中返回它。
只需删除新的字符串[]并离开&#39; img&#39;并将返回类型从String更改为String []
public String[] getYourimages() {
return img ;
}