Reputation: 24630
Basically I have this:
Cursor cur = ...
for (int i = 0; i < cur.getColumnCount(); i++) {
String name = cur.getColumnName(i);
Log.d("dao",name);
int type = cur.getType(i);
... and getting in the getType()
call the above Exception.
The column name is logged correct.
ERROR AndroidRuntime Caused by: android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 0
Upvotes: 0
Views: 384
Reputation: 13957
This is a feature of the SQLite database, that uses dynamic typing. Check this too. Why don't you use:
Cursor cur = ...
if (cursor != null) {
while (cursor.moveToNext()) {
String name = cur.getColumnName(i);
int type = cur.getType(i);
...
}
}
This way you ask only for the type, if a row exist.
If you need the column type independently of any results, you might use:
String tableName = "...";
Cursor cursor = rawQuery("pragma table_info(" +tableName +")");
String type = getString(0);
String name = getString(1);
Hope this helps ... Cheers!
Upvotes: 1