Could not read row 0, column 0 from CursorWindow which has 0 rows, 64 columns

I will get this error in my logcat someday.

Could not read row 0, column 0 from CursorWindow which has 0 rows, 64 columns.

First, a little back. I have an application that works on many devices in our organization. Primarily, it currently works on about 20 Samsung Note 8 devices, 2 Samsung Note 10.1 devices, and a few others. So far the problem is only on two Note 8 devices. It works fine on all other devices.

How the app works, users use the app to collect information, text, photos, signature, etc ... and all of this is then stored / inserted into a SQLite database as a string in a view table. The view table contains 64 columns for each field collected. There is a sync method that always works (this is AsyncTask , which runs inside the runnable thread, so even if the app is closed, it still syncs data in the background unless you close it from the Android Task Manager) which syncs the data with the remote server and checks every 10 seconds if sync is required, for example if a new insert was inserted, it will start syncing this view. When the submission is complete, it syncs with the server and receives a success response, it is then removed from the device database. It has worked fine so far and thousands of views have been successfully synced, etc. However, from time to time I get this error from one or two specific Note 8 tables that reproduce this issue. I've tried many times to create the error, but it always works when I test it and I've tried all types of scripts to test it.

My code is thousands of lines, so I'll try to keep it as up to date as possible. First, here is the relevant code for the runnable:

public Runnable myRunnable = new Runnable()
 {

    @Override
    public void run()
    { 
       count ++;
                if(count >= 10)
                {
                    android.util.Log.w("     SYNC     ", "---------------");
                    android.util.Log.w("     SYNC     ", "Checking if sync method is busy");
                    if(!syncBusy)
                    {
                        android.util.Log.w("     SYNC     ", "Sync method OPEN");
                        doSync();//This will start doing sync.
                        count = 0;
                    }
                    else
                    {
                    android.util.Log.w("     SYNC     ", "Sync method BUSY, will try again in 10 seconds");
                    android.util.Log.w("     SYNC     ", "---------------");
                    }
                }
                if(count == 1 && !syncBusy)
                {
                    checkSubmissionsLefttoSync();
                }
       mHandler.postDelayed(myRunnable, 1000);
    }
};

      

Then the doSync () method is where I am doing the upload and also where I am getting the error. It's over a thousand lines, so I don't want to post any code here. I can say that it works 100% for all devices except for one or two exceptions that cause the above error.

Also, I'll post the part where I actually traverse the database inside the sync method:

        databaseHelper = new Handler_Database(this);
        Cursor cursor2 = databaseHelper.getAllUnsyncedSubmissions();

        if(cursor2.getCount() > 0) 
        {
            if(cursor2.moveToFirst())
            {

              do
                {
                    try
                    {
                       //doing lookups here and populating sync arrays
                    }
                    catch (IllegalStateException e)
                    {
                        //Do Nothing
                    }
                    catch (NullPointerException e)
                    {
                        //Do Nothing
                    }
                }
                while(cursor2.moveToNext());

            }
            else
            {

            }
        }
        else
        {

        }
         cursor2.close();
         databaseHelper.close();

      

I noticed something else and I'm not sure if this is the problem, however, when I start the application, logcat prints out the following line about 6 or 7 times:

12: 48: 11.115 7416 # 7416 DEBUG SQLiteOpenHelper DB version: 60

I have my own warnings when the app starts up and those that only show up once. However, the db version and other information is written multiple times to the logcat. This is problem? Does this mean that my database has some kind of error that creates multiple instances?

All apps are updated with signed apk from playstore . My database's onUpgrade method looks like this:

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
{
    // Drop older table if existed
    db.execSQL("DROP TABLE IF EXISTS " + TABLE_SUBMISSIONS);

    // Create tables again
    onCreate(db);
}

      

This works great for all other tablets and devices. All of them are automatically updated from the play store and continue to work as they should. However, why does logcat print these lines multiple times?

Could this be part of the problem, why am I getting the error as mentioned at the beginning of this post?

Any possible understanding would be greatly appreciated. I have been pulling my hair out for several weeks now and cannot find any flaws in my code.

UPDATE 1:

I just saw this warning:

08: 30: 58.710 16745 # 16745 WARN CursorWindow Window full: requested allocation 307333 bytes, free space 249426 bytes, window size 2097152 bytes

I guess this may be the cause of my problems. Any ideas on how to effectively solve this problem?

UPDATE 2:

I think the solution might be to constrain the columns I get with the cursor. For example, all small text values ​​/ columns. Then after that, create a new query for each of the columns that I know are taking up too much space. Do you think this is the solution? Anyone?

UPDATE 3:

This might work, I think I will be doing large fields in separate cursors after the original is refactored. Something like this (I just wrote the psuedo code):

Cursor c = db.rawQuery("SELECT Column1, Column2 .... FROM table " + ... , ...);

      

Decision:

See my solution here! stack overflow

+3


source to share


2 answers


I finished my solution and it works great now. Basically, the bottom line is that you shouldn't store big data in a sqlite database on Android. When working with images, rather only store the URI and store the image on the device. HOWEVER, if you have to, I recommend not loading all of the image data into the same cursor, splitting it up and doing multiple queries.



Please see my answer here fooobar.com/questions/2175633 / ...

+5


source


This error occurs when your images are large. Save the url of the image or compress the image before saving.



+2


source







All Articles