我是 android 新手,我的光标有问题。我无法使用以下方式访问数据:
cursor.get(cursor.getColumnIndex(columnName));
我尝试了以下代码来测试错误:
while (cursor.moveToNext()) {
int x = 2;
Log.i("MyDebug", "Index: " + x);
Log.i("MyDebug", "Name: " + cursor.getColumnName(x));
Log.i("MyDebug", "Index again: " + cursor.getColumnIndex(cursor.getColumnName(x)));
}
调试监视器的结果:
Index: 2
Name: mainMenu.title
Index again: -1
“再次索引”的结果不应该是2吗?我做错了什么?
最佳答案
cursor.getColumnIndex() 需要列的名称,没有表的名称:
cursor.getColumnIndex("mainMenu.title"); // -1
cursor.getColumnIndex("title"); // 2
关于Android getColumName 和 getColumnIndex,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4511894/
我是android新手,我的光标有问题。我无法使用以下方式访问数据:cursor.get(cursor.getColumnIndex(columnName));我尝试了以下代码来测试错误:while(cursor.moveToNext()){intx=2;Log.i("MyDebug","Index:"+x);Log.i("MyDebug","Name:"+cursor.getColumnName(x));Log.i("MyDebug","Indexagain:"+cursor.getColumnIndex(cursor.getColumnName(x)));}调试监视器的结果:Ind
我是android新手,我的光标有问题。我无法使用以下方式访问数据:cursor.get(cursor.getColumnIndex(columnName));我尝试了以下代码来测试错误:while(cursor.moveToNext()){intx=2;Log.i("MyDebug","Index:"+x);Log.i("MyDebug","Name:"+cursor.getColumnName(x));Log.i("MyDebug","Indexagain:"+cursor.getColumnIndex(cursor.getColumnName(x)));}调试监视器的结果:Ind
在Android中使用SQLiteCursor时,我了解到getColumnIndex()是区分大小写的,例如:示例:数据库中的列名是:Rulescursor.getColumnIndex("Rules")//worksfinecursor.getColumnIndex("rules")//throwserror,seetheerrordetail文档对此没有任何说明,详情pleaseseethis.LogCat说:java.lang.IllegalStateException:Couldn'treadrow0,col-1fromCursorWindow.MakesuretheCurs
在Android中使用SQLiteCursor时,我了解到getColumnIndex()是区分大小写的,例如:示例:数据库中的列名是:Rulescursor.getColumnIndex("Rules")//worksfinecursor.getColumnIndex("rules")//throwserror,seetheerrordetail文档对此没有任何说明,详情pleaseseethis.LogCat说:java.lang.IllegalStateException:Couldn'treadrow0,col-1fromCursorWindow.MakesuretheCurs