- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试检索sqlite数据库的数据。并将其放在字符串上以进一步显示,但我收到此错误,请帮助我解决该错误!
这是显示错误的 logcat 数据
12-31 13:18:55.141: E/1.6(3833): 2222
12-31 13:18:55.191: E/1.2.2(3833): android.database.CursorIndexOutOfBoundsException: Index 9 requested, with a size of 9
12-31 13:18:55.191: E/1.7(3833): 2222
这是显示错误的代码段!
public String getdata() {
// TODO Auto-generated method stub
Log.e("1.1", "2222");
String[] column = new String[]{KEY_ROWID, KEY_NAME, KEY_HOTNESS };
Log.e("1.2", "2222");
Cursor c = ourDatabase.query(DATABASE_TABLE, column, null, null, null, null, null);
Log.e("1.3", "2222");
String result = "";
Log.e("1.4", "2222");
int iRow = c.getColumnIndex(KEY_ROWID);
int iName = c.getColumnIndex(KEY_NAME);
int iHotness = c.getColumnIndex(KEY_HOTNESS);
Log.e("1.5", "2222");
try{
for(c.moveToFirst(); !c.isAfterLast(); c.moveToNext());
{
Log.e("1.6", "2222");
result = result + c.getString(0) + " " + c.getString(1) + " " + c.getString(2) + "\n";
}
}catch(Exception e)
{
Log.e("1.2.2", e.toString());
}
Log.e("1.7", "2222");
return result;
}
注意:将以下代码放入 try catch 后,它会移至下一个 Activity ,但不会显示任何结果数据
for(c.moveToFirst(); !c.isAfterLast(); c.moveToNext());
{
Log.e("1.6", "2222");
result = result + c.getString(0) + " " + c.getString(1) + " " + c.getString(2) + "\n";
}
下一个 Activity 代码:
TextView tv = (TextView) findViewById(R.id.textView3);
Log.e("1", "111111");
HotOrNot info = new HotOrNot(this);
Log.e("2", "111111");
info.open();
Log.e("3", "111111");
String data = info.getdata();
Log.e("4", "111111");
info.close();
Log.e("5", "111111");
tv.setText(data);
Log.e("6", "111111");
}
}
最佳答案
你的分号太多了:
for(c.moveToFirst(); !c.isAfterLast(); c.moveToNext()); // look here :(
...因此您的 for
循环运行到光标末尾。然后,您尝试从光标获取一些数据,但失败了,因为您已经在最后一个条目之后了。
就用这个:
while(c != null && c.moveToNext())
{
Log.e("1.6", "2222");
result = result + c.getString(0) + " "
+ c.getString(1) + " "
+ c.getString(2) + "\n";
}
您很可能可以跳过c != null
。
关于java - 获取 "CursorIndexOutOfBoundsException ",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20858445/
我想使用 List 和 Cursor 将两个值放入 SQLite 数据库中的一个微调器行中,这是我的代码: 将数据放入列表: public List getAllLabelsServer(){
我正在使用以下查询查询数据库: final Cursor subject_cursor = db.rawQuery("SELECT * FROM " + DB.Table.SUBJECT +
我正在尝试检索sqlite数据库的数据。并将其放在字符串上以进一步显示,但我收到此错误,请帮助我解决该错误! 这是显示错误的 logcat 数据 12-31 13:18:55.141: E/1
我正在尝试加载联系人信息并使用 ListView 显示它。但是我得到了一个错误。 我的代码: public class Sync extends ListActivity implements OnC
现在我正在使用 sqllite 存储所有 json 值的 json 应用程序。值存储正确,我正在为 sqllite 获取数据,发生以下错误请帮助我... 12-09 13:51:22.808: ERR
这是我遇到的错误: 07-20 11:04:45.564: E/AndroidRuntime(1905): java.lang.RuntimeException: Unable to start ac
这是我的 LogCat 日志: 08-25 22:35:27.989: ERROR/AndroidRuntime(327): Caused by: android.database.CursorInd
我在使用 Cursors 对 Android 数据库执行 SQLite 查询时遇到问题,如果我尝试使用 getPage,我会得到一个 android.database.CursorIndexOutOf
亲爱的stackoverflowers, 我的 android 应用程序中有一个数据库,我向它发送一个字符串并返回一个游标。这是代码: public Cursor listSearch(String
由于 Android 数据库错误,我的光标导致应用程序崩溃。 CursorIndexOutOfBoundsException: Index -1 requested, with a size of 1
我使用 android studio 在 android 中尝试了一个简单的注册应用程序。我正在尝试制作一个简单的数据库并在其中插入值。我在调试我的应用程序时收到以下无法理解的错误。 FATAL EX
这是错误,它说索引超出范围,但我不知道如何解决它,有一些土耳其语单词但它们并不重要,我认为: E/AndroidRuntime: FATAL EXCEPTION: main Process: com.
所以我一直在尝试在我的 sqlite 数据库中查询我的 Android 应用程序。然而,我的光标似乎也没有像预期的那样工作,因为我可以获得任何结果。 我知道我的数据库中只有 3 个项目,但我在查询中输
这是我的 SqlLite 查询代码,我在其中定义一个方法来从类别中获取颜色类别并将其作为字符串返回给该方法 public String getCategoryColor(String task) {
我刚刚收到使用我的 Android 应用程序的用户的错误报告。 java.lang.RuntimeException: Unable to start activity ComponentInfo{c
我正在尝试在我正在构建的应用程序中分享视频(到社交媒体)。我正在使用需要 Uri 来解析的 Intent 。我试图在一个简单的文件管理器(列表 Activity )上选择项目,然后长按共享它们。因此,
这是我的代码: Log.d("MYTAG", "random number -->" + randomNumber); idRandomCards[i] = cursorTypeZero.getI
我在我的 sqlite 数据库中使用一个配置表。这具有以下组成: private static final String DATABASE_CONFIG_CREATE = "CREATE TA
我一直在努力使用我的一个表字段查询我的 SQLite 数据库。我使用 ForeignId 字段成功查询,但没有使用我的表 QuizTable 的 Available 字段。我希望你能指出我错过的事情。
所以,我的应用程序的用户崩溃报告中有这个错误。这是报告: android.database.CursorIndexOutOfBoundsException: Index 0 requested, wi
我是一名优秀的程序员,十分优秀!