Android SQLIte error: Couldn't read row 0, col 1 from CursorWindow
Column indices start from 0. Your cursor has only 1 column, so replace getString(1)
with getString(0)
to access the only column value there is.
ERROR: Couldn't read row 0, col -1 from CursorWindow. Make sure the Cursor is correctly initialized before accessing data
Apparently, there is no studentname
column in your result set, if c.getColumnIndex("studentname")
is returning -1
.
Couldn't read row 0, col 5 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it
Your cursor has one column SELECT NOTEMEMOS
but you're trying to read the sixth one with getString(5)
. Replace that with getString(0)
to read the only column value.
how to fix java.lang.IllegalStateException: Couldn't read row 0, col 2 from CursorWindow.
thanks everyone , it solve with this code
public Penyakit getPenyakit1(String namaGejal){
SQLiteDatabase db = this.getReadableDatabase();
String[] colums = {nomber,namapen,idPen,namaGej,idGej};
String selection = namapen + " = ?";
String[] selectionArgs = {String.valueOf(namaGejal)};
Cursor cursor = db.query(TABLE_CONTACTS, colums, selection,
selectionArgs, null, null, null);
Penyakit penyakit = new Penyakit();
if (null != cursor) {
cursor.moveToFirst();
penyakit.set_nomber(cursor.getInt(0));
penyakit.set_namaPen(cursor.getString(1));
penyakit.set_idPenyakit(cursor.getInt(2));
penyakit.set_namGej(cursor.getString(3));
penyakit.set_idGejala(cursor.getInt(4));
}else{
penyakit=null;
}
db.close();
return penyakit;
}
android java.lang.IllegalStateException: Couldn't read row 0, col 0 from CursorWindow
01-29 13:41:56.520: W/CursorWindow(4121): Window is full: requested allocation 5140987 bytes, free space 2096617 bytes, window size 2097152 bytes
Android SQLite returns rows in cursor windows that have the maximum size of 2MB as specified by config_cursorWindowSize
. If your row exceeds this limit, you'll get this error.
Storing large data in sqlite database is not a good idea anyway. Store files in filesystem and paths in database.
java.lang.IllegalStateException: Couldn't read row 0, col 2 from CursorWindow
This should be
String username= result.getString(0);
String password=result.getString(1);
Cursor index starts from zero
Full code
SQLiteDatabase myDatabase=openOrCreateDatabase("Login",MODE_PRIVATE,null);
Cursor result=myDatabase.rawQuery("Select * from Login",null);
if (result.moveToFirst()) {
String username= result.getString(0);
String password=result.getString(1);
}
Related Topics
Alertdialog.Getbutton() Method Gives Null Pointer Exception Android
How to Link a Prebuilt Shared Library to an Android Ndk Project
Google Maps API V2 'Failed to Load Map. Could Not Contact Google Servers'
Manipulating Data on Webs in Android
Sqliteopenhelper Onupgrade() Confusion Android
How to Retrieve Key Alias and Key Password for Signed APK in Android Studio(Migrated from Eclipse)
Starting Activity from Fragment Causes Nullpointerexception
Surfaceview Flashes Black on Load
How to Restart Adb Manually from Android Studio
Run Task Before Compilation Using Android Gradle Plugin
Android: Detect Orientation Changed
Error:Connectionresult{Statuscode=Internal_Error, Resolution=Null}
How to Access a File from Asset/Raw Directory
Android L (API 21) - Java.Lang.Illegalargumentexception: Service Intent Must Be Explicit
How to Use the Android Volley API