-1

When I compose the 2MB Mail and sent to my same email id. Then I am trying to reply same mail[2MB]. It was sending. When open the reply mail I am getting the following error.

Error : "java.lang.IllegalStateException: Couldn't read row 0, col 0 from CursorWindow. Make sure the Cursor is initialised correctly before accessing data from it."

Error is coming in this line:

cursor.getString(0);
Iñigo
  • 1,877
  • 7
  • 25
  • 55
user1955234
  • 49
  • 1
  • 2
  • 2MB is too big. Don't store stuff that big in a database. Save it to the file system instead, and store the path(s) in the db. https://stackoverflow.com/q/21432556 – Mike M. Jul 27 '19 at 12:57

3 Answers3

0

Consider first getting column index and then attempting to read the value. Since you didn't post your code, I can only suggest the following:

cursor.getString(cursor.getColumnIndex(0));

For example, your code could look something like this:

String query = "some_query_here";
Cursor cursor = db.rawQuery(query, null);

if(cursor.getCount() > 0) {
   cursor.moveToFirst();
   while(!cursor.isAfterLast()) {
      String result  = cursor.getString(cursor.getColumnIndex(0));
      cursor.moveToNext();
   }
   cursor.close();
} 

Perhaps, you made a mistake in initializing the Cursor object. Consider rechecking your code.

Sergey Emeliyanov
  • 5,158
  • 6
  • 29
  • 52
  • Hi Serj, I have tried your code. its coming into if block and while block . count is 1. but still it throwing the Error : Failed to read row 0, column 0 from a CursorWindow which has 0 rows, 2 columns."java.lang.IllegalStateException: Couldn't read row 0, col 0 from CursorWindow. Make sure the Cursor is initialised correctly before accessing data from it." – user1955234 Jul 27 '19 at 16:54
0

If your Cursor returned any rows then it would contain at least 1 column with index 0, so there would be no error.
But it seems that it is empty (no rows).
All you need to check for the existence of any row is moveToFirst() which returns true if there exists a 1st row (so any row):

if (cursor.moveToFirst()) {
    String columnvalue = cursor.getString(0);  
} else {
    // write your code here
}
forpas
  • 160,666
  • 10
  • 38
  • 76
  • Hi Forpas, Thanks for the reply. I have checked the cursor count. count is 1. then i have checked the cursor.moveToFirst(). it was true. Then its enter into the block. but am facing same the Error : "java.lang.IllegalStateException: Couldn't read row 0, col 0 from CursorWindow. Make sure the Cursor is initialised correctly before accessing data from it." – user1955234 Jul 27 '19 at 05:56
  • Failed to read row 0, column 0 from a CursorWindow which has 0 rows, 2 columns. – user1955234 Jul 27 '19 at 16:58
0

look like your row is having more than 2MB data size so cursor is throwing IllegalStateException.

Arun kumar
  • 1,894
  • 3
  • 22
  • 28