Wondering how to resolve SQlite IllegalStateException that occurs in Cursor? We can help you.
At Bobcares, we offer solutions for every query, big and small, as a part of our Server Management Service.
Let’s take a look at how our Support Team help a customer deal with this error.
How to resolve SQlite IllegalStateException that occurs in Cursor?
A database cursor. Cursors are used for operating on collections of records, for iterating over a database, and for saving handles to individual records, so that they can be modified after they have been read.
Cursors which are open with a transaction instance are transactional cursors and may be used by multiple threads, but only serially.
That is, the application must serialize access to the handle.
Non-transactional cursors, open with a null transaction instance, may not use by multiple threads.
Typically, error might look as shown below:
java.lang.IllegalStateException:
at android.database.CursorWindow.nativeGetString (CursorWindow.java)
at android.database.CursorWindow.getString (CursorWindow.java:438)
at android.database.AbstractWindowedCursor.getString (AbstractWindowedCursor.java:51)
...
Issue occurs if the getColumnIndex (COL_NAME) could not find the Index of COL_NAME and returned -1 as in this answer.
This results in c.getString (-1) and cannot find the column.
Today, let us see the steps followed by our Support Techs to resolve it.
Firstly, try not using getColumnIndex ()
.
Instead use c.getString (1)
Before modification: c.getString (c.getColumnIndex (COL_NAME))
After modification: c.getString (1)
Specifying the column number directly will work.
If you want to use getColumnIndex (COL_NAME)
, -1 will be returned when the column is not found.
Hence, it is better to usegetColumnIndexOrThrow (COL_NAME)
[Need a solution to another query? We are just a click away.]
Conclusion
Today, we saw steps followed by our Support Engineers to resolve SQlite IllegalStateException that occurs in Cursor.
PREVENT YOUR SERVER FROM CRASHING!
Never again lose customers to poor server speed! Let us help you.
Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.
0 Comments