获取最后一个 _id 时出现 CursorIndexOutOfBoundsException?
我正在尝试从数据库插入的最后一行(_id)中提取数据。我不知道我有什么错/遗漏。感谢您的帮助!
ERROR/AndroidRuntime(363): Caused by: android.database.CursorIndexOutOfBoundsException:
Index -1 requested, with a size of 1
爪哇:
else { // Otherwise start the application here:
Cursor c = db.rawQuery(
"SELECT * FROM History_List ORDER BY _id desc limit 1",
null);
int nI = c.getColumnIndexOrThrow("intent");
String intent = c.getString(nI);
Class<?> nIntent = null;
try {
nIntent = Class.forName("com.aeroTechnologies.flyDroid."
+ intent);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
int tvLabel = c.getColumnIndexOrThrow("label");
String label = c.getString(tvLabel);
int tvTitle = c.getColumnIndexOrThrow("title");
String title = c.getString(tvTitle);
int tvDescript = c.getColumnIndexOrThrow("description");
String descript = c.getString(tvDescript);
int tvURL = c.getColumnIndexOrThrow("gotoURL");
String url = c.getString(tvURL);
int yPOS = c.getColumnIndexOrThrow("scrollY");
String ypos = c.getString(yPOS);
Intent i = new Intent(Start.this, nIntent);
i.putExtra("KEY_LABEL", label);
i.putExtra("KEY_TITLE", title);
i.putExtra("KEY_DESCRIPT", descript);
i.putExtra("KEY_URL", url);
i.putExtra("KEY_INTENT", intent);
i.putExtra("KEY_YPOS", ypos);
startActivity(i);
}
I'm trying to pull data from the last row inserted (_id) of a database. I cant figure out what I have wrong / missing. Thnx for the help!!
ERROR/AndroidRuntime(363): Caused by: android.database.CursorIndexOutOfBoundsException:
Index -1 requested, with a size of 1
Java:
else { // Otherwise start the application here:
Cursor c = db.rawQuery(
"SELECT * FROM History_List ORDER BY _id desc limit 1",
null);
int nI = c.getColumnIndexOrThrow("intent");
String intent = c.getString(nI);
Class<?> nIntent = null;
try {
nIntent = Class.forName("com.aeroTechnologies.flyDroid."
+ intent);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
int tvLabel = c.getColumnIndexOrThrow("label");
String label = c.getString(tvLabel);
int tvTitle = c.getColumnIndexOrThrow("title");
String title = c.getString(tvTitle);
int tvDescript = c.getColumnIndexOrThrow("description");
String descript = c.getString(tvDescript);
int tvURL = c.getColumnIndexOrThrow("gotoURL");
String url = c.getString(tvURL);
int yPOS = c.getColumnIndexOrThrow("scrollY");
String ypos = c.getString(yPOS);
Intent i = new Intent(Start.this, nIntent);
i.putExtra("KEY_LABEL", label);
i.putExtra("KEY_TITLE", title);
i.putExtra("KEY_DESCRIPT", descript);
i.putExtra("KEY_URL", url);
i.putExtra("KEY_INTENT", intent);
i.putExtra("KEY_YPOS", ypos);
startActivity(i);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将光标分配给
c
后,放置c.moveToFirst();
将其移动到行中的第一个元素。所以,你将拥有
After you assign the cursor to
c
, put ac.moveToFirst();
to move it to the first element in line.So, you'll have