Android SQLiteDiskIOException (code 522 SQLITE_IOERR_SHORT_READ) - android

I am on Android O and using Room database, from time to time, I experience SQLiteDisckIOException, I try to troubleshoot problem but the stack doesn't tell me where the failing point is. Can some give me some hint or how to troubleshoot this kind of problem and what is the potential problem here? The app that I am writing will write to database when location change, and also there are couple background task that periodic update database when needed.
Here is the stack I see:
10-07 22:29:41.404 22214-22226/? E/DataBuffer: Internal data leak within a DataBuffer object detected! Be sure to explicitly call release() on all DataBuffer extending objects when you are done with them. (internal object: com.google.android.gms.common.data.DataHolder#b0fef92)
10-07 22:29:41.405 22214-22226/? E/DataBuffer: Internal data leak within a DataBuffer object detected! Be sure to explicitly call release() on all DataBuffer extending objects when you are done with them. (internal object: com.google.android.gms.common.data.DataHolder#db3ad63)
10-07 22:29:41.415 19847-19847/com.firsapp.testing E/Periodic: from PIM->onCreateOptionMenu
10-07 22:29:41.442 19847-21824/com.firsapp.testing E/SQLiteLog: (522) statement aborts at 7: [SELECT DISTINCT tag FROM worktag WHERE work_spec_id=?] disk I/O error
10-07 22:29:41.443 19847-21824/com.firsapp.testing E/SQLiteQuery: exception: disk I/O error (code 522 SQLITE_IOERR_SHORT_READ); query: SELECT DISTINCT tag FROM worktag WHERE work_spec_id=?
10-07 22:29:41.449 19847-21824/com.firsapp.testing E/AndroidRuntime: FATAL EXCEPTION: pool-6-thread-2
Process: com.firsapp.testing, PID: 19847
android.database.sqlite.SQLiteDiskIOException: disk I/O error (code 522 SQLITE_IOERR_SHORT_READ)
at android.database.sqlite.SQLiteConnection.nativeExecuteForCursorWindow(Native Method)
at android.database.sqlite.SQLiteConnection.executeForCursorWindow(SQLiteConnection.java:859)
at android.database.sqlite.SQLiteSession.executeForCursorWindow(SQLiteSession.java:836)
at android.database.sqlite.SQLiteQuery.fillWindow(SQLiteQuery.java:62)
at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:149)
at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:137)
at androidx.work.impl.model.WorkTagDao_Impl.getTagsForWorkSpecId(WorkTagDao_Impl.java:92)
at androidx.work.impl.WorkerWrapper.run(WorkerWrapper.java:102)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764)
10-07 22:29:41.579 890-890/? E/lowmemorykiller: Error writing /proc/19847/oom_score_adj; errno=22

From the SQLite documentation SQLITE_IOERR_SHORT_READ refers to a case where the database was unable to read the requested number of bytes from the file system.
https://www.sqlite.org/rescode.html#ioerr_short_read
Do you allow your apps to be installed on the external storage directory ?
https://developer.android.com/guide/topics/manifest/manifest-element.html#install
My guess is that:
Either the file system on the device is problematic.
The app was in an external storage directory, and the SD card was removed while the user was using your app, and that caused SQLite to throw this exception.

Related

android studio SQL lite database error (android.database.sqlite.SQLiteException)

I copy/paste the already created .db file to my android studio project, but it is crashing my app. That database file is working fine on another android studio project but it is giving exceptions and causing the app to crash on my current project. Following is the logcat
2022-05-26 19:42:18.147 21758-21758/com.learning.kidslearningzone E/TAG: setAppAdId:BeforeChange::::: ca-app-pub-3940256099942544~3347511713
2022-05-26 19:42:18.147 21758-21758/com.learning.kidslearningzone E/TAG: setAppAdId:AfterChange:::: ca-app-pub-3940256099942544~3347511713
2022-05-26 19:42:30.180 21758-21758/com.learning.kidslearningzone E/SQLiteLog: (1) no such table: kids in "SELECT * FROM kids WHERE id=2"
2022-05-26 19:42:30.183 21758-21758/com.learning.kidslearningzone E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.learning.kidslearningzone, PID: 21758
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.learning.kidslearningzone/com.learning.kidslearningzone.Courses.ListVideoActivity}: android.database.sqlite.SQLiteException: no such table: kids (code 1 SQLITE_ERROR[1]): , while compiling: SELECT * FROM kids WHERE id=2
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3835)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4011)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2325)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:246)
at android.app.ActivityThread.main(ActivityThread.java:8633)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
Caused by: android.database.sqlite.SQLiteException: no such table: kids (code 1 SQLITE_ERROR[1]): , while compiling: SELECT * FROM kids WHERE id=2
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:1463)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:901)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:590)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:62)
at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:46)
at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:2063)
at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:2002)
at com.learning.kidslearningzone.Databases.DatabaseHelper.getVideoDetails(DatabaseHelper.kt:20)
at com.learning.kidslearningzone.Courses.ListVideoActivity.setRvVideoListAdapter(ListVideoActivity.java:60)
at com.learning.kidslearningzone.Courses.ListVideoActivity.initDefine(ListVideoActivity.java:49)
at com.learning.kidslearningzone.Courses.ListVideoActivity.onCreate(ListVideoActivity.java:39)
at android.app.Activity.performCreate(Activity.java:8207)
at android.app.Activity.performCreate(Activity.java:8191)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3808)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4011) 
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) 
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2325) 
at android.os.Handler.dispatchMessage(Handler.java:106) 
at android.os.Looper.loop(Looper.java:246) 
at android.app.ActivityThread.main(ActivityThread.java:8633) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
 
plz someone tell me what is the problem or what i have done wrong. Thanks
Every project has its own database may it be Room or Sqlite once you build your project the database will be created locally, so it is unique to the project and your need to add elements manually. What you did is you brought that file to another project and the query which you wrote is very SUS cause your present project database do not have any id:2 entry so it is failing.
You cannot just cut and paste the database into the project. For such a pre-existing database you would typically copy and paste the database into the assets folder and then use an adapted custom class that extends SQLiteOpenHelper (from your stack trace Databases.DatabaseHelper).
This adapted custom class MUST, in addition to the usual implementation have code that will:-
check to see if the database already exists.
if the database file does not exists copy the database file from the assets folder to the ultimate location (typically data/data/<the_package_name>/databases/<the_database_file_name)
Should the database then not exist (if no exception has stopped the app) or if the database is corrupt then the database will be created WITHOUT anything but the sqlite_master table and the android_metadata table, so effectively , from the user/developer viewpoint, an empty database and hence a table not found.
I would suspect that this is what is happening.
However, another scenario where this can happen if exceptions are caught/trapped and allow processing to continue. Is when the SQLiteDatabase's getWritableDatabase or getReadableDatabase are used for later Android versions when WAL (Write-Ahead Logging is the default). In short this creates a -wal file, which is NOT owned by the original database file created by the methods as that database file has been overwritten by the one copied from the asset. The too friendly openOrCreate method used then sees the corrupt database and gives you a new database devoid of any tables.
It is suggested that one of the above is the issue that you face. Although a bit over the top this may be of use.

An error occurs when running android apllication that implements tensorflow-lite on a specific device

An error occurs when running android apllication that implements tensorflow-lite on a specific device.
ex)LG X4, LG Q52
I get an error when calling function -> tfLite.runForMultipleInputsOutputs(inputArray, outputMap);
This is my error log.
E/AndroidRuntime: FATAL EXCEPTION: inference
Process: org.tensorflow.lite.examples.detection, PID: 13469
java.lang.IllegalArgumentException: Internal error: Failed to run on the given Interpreter: Next operations are not supported by GPU delegate:
ADD:
CONCATENATION:
CONV_2D:
EXP: Operation is not supported.
LEAKY_RELU:
LOGISTIC:
MAX_POOL_2D:
MUL:
RESHAPE:
RESIZE_BILINEAR:
SPLIT: Operation is not supported.
SPLIT_V: Operation is not supported.
STRIDED_SLICE:
SUB: Expected 2 input tensor(s), but node has 1 runtime input(s).
First 61 operations will run on the GPU, and the remaining 144 on the CPU.
OpenCL library not loaded - dlopen fai
at org.tensorflow.lite.NativeInterpreterWrapper.run(Native Method)
at org.tensorflow.lite.NativeInterpreterWrapper.run(NativeInterpreterWrapper.java:154)
at org.tensorflow.lite.Interpreter.runForMultipleInputsOutputs(Interpreter.java:314)
at org.tensorflow.lite.examples.detection.tflite.YoloV4Classifier.getDetectionsForTiny(YoloV4Classifier.java:421)
at org.tensorflow.lite.examples.detection.tflite.YoloV4Classifier.recognizeImage(YoloV4Classifier.java:461)
at org.tensorflow.lite.examples.detection.tflite.YoloV4Classifier.recognizeImage(YoloV4Classifier.java:50)
at org.tensorflow.lite.examples.detection.DetectorActivity$3.run(DetectorActivity.java:304)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:214)
at android.os.HandlerThread.run(HandlerThread.java:67)
I/Process: Sending signal. PID: 13469 SIG: 9
Connected to process 13858 on device 'lge-lm_q520n-LMQ520NOFAIMNHYEMS'.
please help me
You did not provide additional details if it is working on other devices or how the model was generated. I have faced this error before. It is likely not device related. Based on the error log it seems you are using this repository for object detection task with yolov4 tflite model.
java.lang.IllegalArgumentException: Internal error: Failed to run on the given Interpreter: Next operations are not supported by GPU delegate:
EXP: Operation is not supported.
SPLIT: Operation is not supported.
SPLIT_V: Operation is not supported.
Use tf.lite.OpsSet.SELECT_TF_OPS in converter.target_spec.supported_ops when converting saved model to tflite. Also in build.gradle use any one of the below,
implementation 'org.tensorflow:tensorflow-lite-select-tf-ops:2.3.0'
implementation 'org.tensorflow:tensorflow-lite-select-tf-ops:0.0.0-nightly'.
This will increase apk size but this can solved with selective build of tensorflow-lite-select-tf-ops.aar.

Getting Fatal exception on different Android devices using RushORM database

Below is the details of the exception that is according to different Android devices and unable to find any soliton for it.
I get these details from Firebase Crashlytics as I am unable to reproduce it and is the most frequently according to crash in my Firebase Crashlytics list
Fatal Exception: android.database.sqlite.SQLiteDiskIOException: disk I/O error (code 778)
Error Code : 778 (SQLITE_IOERR_WRITE)
Caused By : Disk I/O error occurred during 'write' operation.
(disk I/O error (code 778))
#
at android.database.sqlite.SQLiteConnection.nativeExecuteForChangedRowCount(SQLiteConnection.java)
at android.database.sqlite.SQLiteConnection.executeForChangedRowCount(SQLiteConnection.java:816)
at android.database.sqlite.SQLiteSession.executeForChangedRowCount(SQLiteSession.java:754)
at android.database.sqlite.SQLiteStatement.executeUpdateDelete(SQLiteStatement.java:64)
at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:2067)
at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1996)
at co.uk.rushorm.android.AndroidRushStatementRunner.runRaw(AndroidRushStatementRunner.java:37)
at co.uk.rushorm.core.RushCore$12.statementCreated(RushCore.java:473)
at co.uk.rushorm.core.implementation.ReflectionTableStatementGenerator.generateStatements(ReflectionTableStatementGenerator.java:46)
at co.uk.rushorm.core.RushCore.createTables(RushCore.java:469)
at co.uk.rushorm.core.RushCore.access$200(RushCore.java:39)
at co.uk.rushorm.core.RushCore$13.createClasses(RushCore.java:495)
at co.uk.rushorm.core.implementation.ReflectionUpgradeManager.upgrade(ReflectionUpgradeManager.java:119)
at co.uk.rushorm.core.RushCore.upgrade(RushCore.java:480)
at co.uk.rushorm.core.RushCore.access$300(RushCore.java:39)
at co.uk.rushorm.core.RushCore$1.run(RushCore.java:132)
at java.lang.Thread.run(Thread.java:762)

[Android]: Firebase database causes SQLiteDatabaseLockedException

We used Firebase Database to synchronize data and we found an exception in crash report. Here is brief log:
Caused by com.google.firebase.database.DatabaseException:
Failed to gain exclusive lock to Firebase Database's offline persistence.
...
Caused by android.database.sqlite.SQLiteDatabaseLockedException: database is locked (code 5): ,
while compiling: PRAGMA journal_mode
More detail log is here. Here is our Firebase Database init code
// run in Application onCreate method
FirebaseDatabase.getInstance().setPersistenceEnabled(true);
Mostly, HTC mobiles with API level 19 are impact. We try to reproduce this
bug, but fail.

what does this error means?

i got lots of crashes on lots of devices but on my device(lg p920) it works fine. the below report is from goggle play my app crashed and got 6 reports. by the way i use sql pre created database.and also created android_metadata table and locale en_US also inserted to that database.
this is the STACK TRACES:
android.database.sqlite.SQLiteDiskIOException: disk I/O error
at android.database.sqlite.SQLiteDatabase.native_setLocale(Native Method)
at android.database.sqlite.SQLiteDatabase.setLocale(SQLiteDatabase.java:2074)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:1014)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:986)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:962)
at offline.sinhaladic.com.MainActivity.sugen(MainActivity.java:1312)
at offline.sinhaladic.com.MainActivity$7.afterTextChanged(MainActivity.java:972)
at android.widget.TextView.sendAfterTextChanged(TextView.java:7665)
at android.widget.TextView$ChangeWatcher.afterTextChanged(TextView.java:8067)
at android.text.SpannableStringBuilder.sendTextHasChanged(SpannableStringBuilder.java:900)
at android.text.SpannableStringBuilder.change(SpannableStringBuilder.java:353)
at android.text.SpannableStringBuilder.change(SpannableStringBuilder.java:266)
at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:443)
at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:420)
at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:29)
at android.view.inputmethod.BaseInputConnection.replaceText(BaseInputConnection.java:663)
at android.view.inputmethod.BaseInputConnection.setComposingText(BaseInputConnection.java:425)
at com.android.internal.view.IInputConnectionWrapper.executeMessage(IInputConnectionWrapper.java:333)
at com.android.internal.view.IInputConnectionWrapper$MyHandler.handleMessage(IInputConnectionWrapper.java:77)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
Reference : https://stackoverflow.com/a/4828540/1318946
One thought that popped up is the hard coded path to where the
database file is located. DB_PATH =
“/data/data/YOUR_PACKAGE/databases/”;
I guess it is possible that this path isn’t valid on Android 2.2.1 for
Desire HD. I exchanged this path with: Environment.getDataDirectory()
+ “/data/YOUR_PACKAGE/databases/” + DB_NAME;
I’ll try to pin point the issue when I had the chance to test on the
actual phone myself. If anyone test this solution, please let me know
if it solves it.
This is not a common error you'll see. It can happen rarely on some device with low internal memory. While your app was trying to write to DB, it ran out of internal memory and failed to write. What you can do is check the available storage and if its really dropping to zero, notify user.
SQLiteDiskIOException
java.lang.Object
↳ java.lang.Throwable
↳ java.lang.Exception
↳ java.lang.RuntimeException
↳ android.database.SQLException
↳ android.database.sqlite.SQLiteException
↳ android.database.sqlite.SQLiteDiskIOException
An exception that indicates that an IO error occured while accessing the SQLite database file.
Reference: SQLiteDiskIOException.

Categories

Resources