Cursor.hasNext抛出java.util.NoSuchElementException 公共字符串ForDate(字符串日期){ MongoCursor=collection.find(eq(“date”,date)).iterator(); basicb=新的basicb(); while(cursor.hasNext()){ b、 setdepartment(cursor.next().getString(“department”); b、 setText(cursor.next().getString(“text”); b、 setTitle(cursor.next().getString(“title”); a.添加(b); } }
我只想从mongodb信息中创建对象,但当我执行此方法时,get make some object但总是返回errorjava.util.NoSuchElementException。可能,问题是您在一个循环中调用了三次Cursor.hasNext抛出java.util.NoSuchElementException 公共字符串ForDate(字符串日期){ MongoCursor=collection.find(eq(“date”,date)).iterator(); basicb=新的basicb(); while(cursor.hasNext()){ b、 setdepartment(cursor.next().getString(“department”); b、 setText(cursor.next().getString(“text”); b、 setTitle(cursor.next().getString(“title”); a.添加(b); } },java,mongodb,mongodb-query,Java,Mongodb,Mongodb Query,我只想从mongodb信息中创建对象,但当我执行此方法时,get make some object但总是返回errorjava.util.NoSuchElementException。可能,问题是您在一个循环中调用了三次next方法。您应该调用它一次并将其结果存储在变量中,因为next检索迭代中的下一个元素 public String ForDate(String date) { MongoCursor<Document> cursor = collection.find(e
next
方法。您应该调用它一次并将其结果存储在变量中,因为next
检索迭代中的下一个元素
public String ForDate(String date) {
MongoCursor<Document> cursor = collection.find(eq("date", date)).iterator();
basicb b = new basicb();
while (cursor.hasNext()) {
b.setDepartament(cursor.next().getString("departament"));
b.setText(cursor.next().getString("text"));
b.setTitle(cursor.next().getString("title"));
lista.add(b);
}
}
问题可能是在一个循环中调用
next
方法三次。您应该调用它一次并将其结果存储在变量中,因为next
检索迭代中的下一个元素
public String ForDate(String date) {
MongoCursor<Document> cursor = collection.find(eq("date", date)).iterator();
basicb b = new basicb();
while (cursor.hasNext()) {
b.setDepartament(cursor.next().getString("departament"));
b.setText(cursor.next().getString("text"));
b.setTitle(cursor.next().getString("title"));
lista.add(b);
}
}
谢谢你的回答,我正在尝试declate类型,但需要导入,我应该导入什么?显示一个大列表xDby
类型
我指的是光标中元素的类型-文档
谢谢你的回答,我正在尝试删除类型,但需要导入,我应该导入什么?显示一个大列表xDbyType
我指的是光标中元素的类型-文档