Cursor.hasNext throws java.util.NoSuchElementException

后端 未结 1 1982
名媛妹妹
名媛妹妹 2021-01-26 09:15
public String ForDate(String date) {
    MongoCursor cursor = collection.find(eq(\"date\", date)).iterator();
    basicb b = new basicb();
    while (cur         


        
1条回答
  •  离开以前
    2021-01-26 10:03

    Probably, the problem is that you are calling next method three times in a single loop. You should call it once and store its result in a variable, since next retrieves next element in the iteration

    while (cursor.hasNext()) {
       Document element = cursor.next();
       b.setDepartament(element.getString("departament"));
       b.setText(element.getString("text"));
       b.setTitle(element.getString("title"));
       lista.add(b);
    }
    

    0 讨论(0)
提交回复
热议问题