简体   繁体   English

无法到达ArrayList内容

[英]Can't reach ArrayList content

I've been parsing XML into ArrayList using Xsrteam. 我一直在使用Xsrteam将XML解析为ArrayList。 It worked but for some reason I can't reach array's content. 它起作用了,但是由于某种原因我无法到达数组的内容。

Classes which handle ArrayList data: 处理ArrayList数据的类:

@XStreamAlias("BOARDS")
public class Boards {
    @XStreamImplicit(itemFieldName = "id")
    public ArrayList ids = new ArrayList();

    //region GETTERS-SETTERS
    public void setIds(ArrayList temp){
        this.ids = temp;
    }
    public List getIds(){
        return ids;
    }
//    endregion
}

@XStreamAlias("id")
class Id {

    @XStreamAlias("board")
    private String board;

    @XStreamAlias("description")
    private String description;

    @XStreamAlias("price")
    private String price;

    @XStreamAlias("shape")
    private String shape;

    @XStreamAlias("riding_level")
    private String ridingLevel;

    @XStreamAlias("riding_style")
    private String ridingStyle;

    @XStreamAlias("camber_profile")
    private String camber;

    @XStreamAlias("stance")
    private String stance;

    @XStreamAlias("picture")
    private String picture;

    <<public getters - setters here>>
}

How I tried to access those getters : 我如何尝试访问这些getters

Boards boards = (Boards) xstream.fromXML(reader); // parse xml into array list
boards.getIds().get(0).getPrice(); //!!getPrice() cannot be resolved

first is Object first = boards.getIds().get(0); firstObject first = boards.getIds().get(0);

Here what it looks like using debugger: 这是使用调试器的外观:

在此处输入图片说明

Boards has a raw type, because of that it is unclear, what object types should be inside ArrayList ids . Boards有一个原始类型,因为不清楚,在ArrayList ids应该包含哪些对象类型。 So, you should either cast result of boards.getIds().get(0) explicitly: 因此,您应该显式地boards.getIds().get(0)

((Id) boards.getIds().get(0)).getPrice()

or generify Boards class: 或扩大Boards类别:

public class Boards<E> {

    public List<E> ids = new ArrayList<E>();

    //region GETTERS-SETTERS
    public void setIds(ArrayList<E> temp){
        this.ids = temp;
    }
    public List<E> getIds(){
        return ids;
    }
//    endregion
}

You can read about generics here 您可以在此处阅读有关泛型的信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM