繁体   English   中英

在Java Gxt中的ListStore上进行迭代

[英]Iteration over a ListStore in Java Gxt

因此,我正在使用Java中的网格小部件...,并且尝试遍历ListStore时遇到以下错误。

[javac]   required: array or java.lang.Iterable
[javac]   found:    ListStore<String>

关于如何解决此问题/为此创建迭代器的任何提示?

这是我的代码:

public void cycle(ListStore<String> line_data){

    for(LineObject line: line_data){
          //Other code goes here
    }


}

如javadoc所示, 列表存储未实现Iterable 因此,您不能使用for每个循环对其进行迭代。

只需使用GETALL()列表存储的方法,该方法将返回一个java.util.List的哪个正确实现可迭代。

但是另一个问题是,您尝试使用LineObject进行迭代,因为您的ListStore是使用String声明的,即ListStore<String>而不是ListStore<LineObject> LineObject该方法将无法正常工作

这是一些示例代码:

public void cycle(ListStore<String> line_data){

    List<String> lineListData = line_data.getAll();

    //for(LineObject line: lineListData){ <-- won't work since you are using Strings

    for(String line: lineListData){ // <-- this will work but probably not what you want
          //Other code goes here
    }

}

回顾对问题的编辑,您可能只想使用LineObject

public void cycle(ListStore<LineObject> line_data){

    List<LineObject> lineListData = line_data.getAll();

    for(LineObject line: lineListData){
          //Other code goes here
    }

}

暂无
暂无

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

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