Android Question Emulator works, device not

TheRealMatze

Active Member
Licensed User
Hi,
i havn´t check on a real device for a week or two, only in the emulator and in release-mode - not a good idea as i see now.

The situation is: One device is unable to sync the data from the server complete. I have a sub checking if a row-guid is already there and, depending of the result, rthe row will updated or inserted. The errorline is when i check the resultset´s rowcount > If result.rowcount=0 Then ...

B4X:
Error occurred on line: 450 (database)
android.database.CursorWindowAllocationException: Cursor window allocation of 2048 kb failed. # Open Cursors=729 (# cursors opened by this proc=729)
    at android.database.CursorWindow.<init>(CursorWindow.java:108)
    at android.database.AbstractWindowedCursor.clearOrCreateWindow(AbstractWindowedCursor.java:198)
    at android.database.sqlite.SQLiteCursor.clearOrCreateWindow(SQLiteCursor.java:316)
    at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:142)
    at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:136)
    at anywheresoftware.b4a.sql.SQL$CursorWrapper.getRowCount(SQL.java:335)
    at vsoft.sedatacollector.database._updateanimal(database.java:1173)
    at vsoft.sedatacollector.sync$ResumableSub_syncNow.resume(sync.java:868)
    at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resumeAsUserSub(DebugResumableSub.java:48)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
    at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resume(DebugResumableSub.java:43)
    at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:267)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:137)
    at anywheresoftware.b4a.BA$2.run(BA.java:387)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:145)
    at android.app.ActivityThread.main(ActivityThread.java:5944)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1388)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1183)

At this time there are already 600 entry´s copied. Source is a json.

The second error is also a little strange. It´s only in debug-mode, not in release-mode. It occours when VisibleRangeChanged is fired on a custom list view. Problem line is p.LoadLayout("item").
this layout contains a panel and 6 lables, no button! But the message says

B4X:
Error occurred on line: 72 (xxxxxxxx)
java.lang.RuntimeException: java.lang.RuntimeException: Cannot convert: class anywheresoftware.b4a.objects.LabelWrapper, to: class anywheresoftware.b4a.objects.ButtonWrapper
    at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:170)
    at anywheresoftware.b4a.objects.PanelWrapper.LoadLayout(PanelWrapper.java:134)
    at anywheresoftware.b4a.objects.B4XViewWrapper.LoadLayout(B4XViewWrapper.java:312)
    at vsoft.sedatacollector.xxxxxxxx._clv1_visiblerangechanged(farmlist.java:708)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at anywheresoftware.b4a.BA$2.run(BA.java:387)
    at android.os.Handler.handleCallback(Handler.java:938)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:245)
    at android.app.ActivityThread.main(ActivityThread.java:8024)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:631)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:978)
Caused by: java.lang.RuntimeException: Cannot convert: class anywheresoftware.b4a.objects.LabelWrapper, to: class anywheresoftware.b4a.objects.ButtonWrapper
    at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayoutHelper(LayoutBuilder.java:409)
    at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayoutHelper(LayoutBuilder.java:453)
    at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:148)
    ... 17 more

Maybe i can ignore that, but i don´t think so. If i understand it right there is a wrong type (button instead of label) - but there is no button :.)

Any hint where i have to start my search?

Regards
 

DonManfred

Expert
Licensed User
Longtime User
Any hint where i have to start my search?
Start with the error.
Cursor window allocation of 2048 kb failed.
Android Cursor size in SQLite can not exceed 2mb.

Whatever you are doing: Do it is smaller parts.
If you are writing to the db, write some entries. Save another some when finished.

If you are reading: Limit your reading to x entries and load more if you need more.
 
Upvote 0

TheRealMatze

Active Member
Licensed User
Start with the error.

Android Cursor size in SQLite can not exceed 2mb.

Whatever you are doing: Do it is smaller parts.
If you are writing to the db, write some entries. Save another some when finished.

If you are reading: Limit your reading to x entries and load more if you need more.
In this point i´m writing. The source is a json load it in a sub from the webserver. Then i parse it and send it row by row to the sub which writes to the database (and failed in this case). Most of the query´s are ExecNonQuery, only the validation if the entry is already there is reading something. I see i have a forgotten .close. After adding these it looks better.
Edit: after ~20k entrys i got a popup that the app did not responde. i can select "wait" or "ok". i have already included a sleep(1) after each database.operation. that makes it better, but not good enought. what can i do to let the os know the app is up and running?

But you say when reading, limit reading - do i understand right, the full query, the sum of all columns and all rows including in the query can´t exeed 2mb?

Any idea for the second error in debug mode?
 
Last edited:
Upvote 0

TheRealMatze

Active Member
Licensed User
I have also found this hint, but i do not understand how to use it... On the first time i have only inserts, after that i have ~100 updates . It is possible to merge it together so far - is there a possibility to use batch-querys without arrays behind, like

sql.addnonqueryttobatch("insert into x(x) values(1)")
sql.addnonqueryttobatch("insert into x(x) values(2)")
sql.addnonqueryttobatch("insert into x(x) values(3)")
...
sql.addnonqueryttobatch("insert into x(x) values(99)")

sql.ExecNonQueryBatch

It looks like it works (with null as second parameter), but the speed did not increase. I use the following code:

B4X:
Sub SQLE_Bulk(s As String)
    sql1.AddNonQueryToBatch(s,Null)  
End Sub

Sub SQLE_ExecuteBulk()
    sql1.ExecNonQueryBatch("SQL1")
    Log(">Run Query")
End Sub

Sub SQL1_NonQueryComplete (Success As Boolean)
    Log(">Query Complete State: " & Success)
End Sub

I call SQLE_ExecuteBulk every 500 Rows and at the end. At the beginning of the sync i set p.KeepAlive(True), so the phone did not sleep. With this the sync works, but it needs the same time as before... After that it works, but the second error stays... ^ "Cannot convert: class anywheresoftware.b4a.objects.LabelWrapper, to: class anywheresoftware.b4a.objects.ButtonWrapper"

Edit: Found the second error - i have accidentally defined one of the labels as button in the global-section.
Edit 2: After some measuring i found out that the selects are the time-consuming parts... More keys in the tables helps a lot!
 
Last edited:
Upvote 0
Top