Android Question Sqlite Read Base64 String Error

BensonHung

Member
Licensed User
Longtime User
I will convert the image to base64 and insert to sqlite.
But when I read sqlite, it is an error:
java.lang.IllegalStateException: Couldn't read row 0, col 1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.
at android.database.CursorWindow.nativeGetString(Native Method)
at android.database.CursorWindow.getString(CursorWindow.java:438)
at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:51)
at anywheresoftware.b4a.sql.SQL$CursorWrapper.GetString(SQL.java:355)
at com.kyhid.quotation.checksendquotationtemp._btnsend_click(checksendquotationtemp.java:862)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:157)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:153)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:78)
at android.view.View.performClick(View.java:4377)
at android.view.View$PerformClick.run(View.java:18031)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5306)
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:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(Native Method)
my code:
B4X:
        CursorDBPoint1= SQLcmd.ExecQuery("select * from FileTemp")      
        For ii = 0 To CursorDBPoint1.RowCount - 1
            CursorDBPoint1.Position = ii
            Dim fileName,fileLink As String
            fileName = CursorDBPoint1.GetString("fileBase64")
        Next
What can I do ?
Thanks everyone~
 

BensonHung

Member
Licensed User
Longtime User
Thank you Erel

Column name is correct.
Some phones can properly run,Some phones error occurs.

sqlite file link: https://drive.google.com/file/d/0B9iUMNet17OwdFprWjBlandFa1U/view?usp=sharing

image to base64 code
B4X:
        Dim Base64Con As Base64Image
        Dim B64Str As String = Base64Con.EncodeFromImage(File.DirDefaultExternal, "123.jpg")
        Dim Insstr As String
        Insstr = "INSERT INTO QuotationTempFile(fileBase64) VALUES('"& B64Str &"')"
        SQLcmd.ExecNonQuery(Insstr)

Search base64 code
B4X:
        Dim fileName As String
        CursorDBPoint1= SQLcmd.ExecQuery("select * from QuotationTempFile")   
        For ii = 0 To CursorDBPoint1.RowCount - 1
            CursorDBPoint1.Position = ii
            fileName = CursorDBPoint1.GetString("fileBase64")
        Next
 
Upvote 0
Top