Android Question How Can i turn this sub to resumable sub that can be called multiple times

omo

Active Member
Licensed User
Longtime User
I have a code below that is working only for one instance. It only allows one time call and then throw b4xview uninitialized error when trying to call it more than one. I tried tracing the uninitialized b4xview but to no success. Here is the code sub and how it was called:

B4X:
Private Sub b4xtable(pnl As B4XView ,maxrow As Int,tag As Object,tblnameb As String,tblcountb As String) 'As ResumableSub 'As B4XTable
    'Use: b4xtable(98%x, 300dip, Pnl2)

   
    'pnl.SetLayoutAnimated(0, 0, 0, Width, Height)
    pnl.LoadLayout("B4XT")
   
   
    Dim tblname As String = tblnameb '"tbl1x"
    Dim tblcount As String = tblcountb '"5"
   
    B4XTable1.mBase.Tag = "B4XTableb" & tag
   
               
    Sleep(0)
    B4XTable1.pnlHeader.Visible = False
   
    B4XTable1.RowHeight = 40dip '30dip
    B4XTable1.HeadersHeight = 40dip '30dip
    B4XTable1.MaximumRowsPerPage = maxrow '4 'make it variable name
    B4XTable1.BuildLayoutsCache(maxrow) '4

    B4XTable1.mBase.Top = -58dip '-60 'to move table to top to cover empty rows
   

    Try

   
        '
        If (tblcount = "5" ) Then
           
            B4XTable1.AddColumn("id", B4XTable1.COLUMN_TYPE_NUMBERS)
            B4XTable1.AddColumn("t1", B4XTable1.COLUMN_TYPE_TEXT)
            B4XTable1.AddColumn("t2", B4XTable1.COLUMN_TYPE_TEXT)
            B4XTable1.AddColumn("t3", B4XTable1.COLUMN_TYPE_TEXT)
            B4XTable1.AddColumn("t4", B4XTable1.COLUMN_TYPE_TEXT)
            B4XTable1.AddColumn("t5", B4XTable1.COLUMN_TYPE_TEXT)
        End If          
'  
        If (tblcount = "6" ) Then
           
            B4XTable1.AddColumn("id", B4XTable1.COLUMN_TYPE_NUMBERS)
            B4XTable1.AddColumn("t1", B4XTable1.COLUMN_TYPE_TEXT)
            B4XTable1.AddColumn("t2", B4XTable1.COLUMN_TYPE_TEXT)
            B4XTable1.AddColumn("t3", B4XTable1.COLUMN_TYPE_TEXT)
            B4XTable1.AddColumn("t4", B4XTable1.COLUMN_TYPE_TEXT)
            B4XTable1.AddColumn("t5", B4XTable1.COLUMN_TYPE_TEXT)
            B4XTable1.AddColumn("t6", B4XTable1.COLUMN_TYPE_TEXT)
        End If  
   
        If (tblcount = "7" ) Then
       
            B4XTable1.AddColumn("id", B4XTable1.COLUMN_TYPE_NUMBERS)
            B4XTable1.AddColumn("t1", B4XTable1.COLUMN_TYPE_TEXT)
            B4XTable1.AddColumn("t2", B4XTable1.COLUMN_TYPE_TEXT)
            B4XTable1.AddColumn("t3", B4XTable1.COLUMN_TYPE_TEXT)
            B4XTable1.AddColumn("t4", B4XTable1.COLUMN_TYPE_TEXT)
            B4XTable1.AddColumn("t5", B4XTable1.COLUMN_TYPE_TEXT)
            B4XTable1.AddColumn("t6", B4XTable1.COLUMN_TYPE_TEXT)
            B4XTable1.AddColumn("t7", B4XTable1.COLUMN_TYPE_TEXT)
   

        End If

   
        Dim Data As List
        Data.Initialize
       
        If (tblcount = "5") Then
            Dim res As ResultSet = B4XPages.MainPage.SQL1.ExecQuery($"SELECT id,tablenamearray,tablecount,t1,t2,t3,t4,t5 FROM alltable WHERE tablenamearray ='${tblname}' and tablecount ='${tblcount}'"$)
        End If
   
        If (tblcount = "6") Then
            Dim res As ResultSet = B4XPages.MainPage.SQL1.ExecQuery($"SELECT id,tablenamearray,tablecount,t1,t2,t3,t4,t5,t6 FROM alltable WHERE tablenamearray ='${tblname}' and tablecount ='${tblcount}'"$)
        End If
   
        If (tblcount = "7") Then
            Dim res As ResultSet = B4XPages.MainPage.SQL1.ExecQuery($"SELECT id,tablenamearray,tablecount,t1,t2,t3,t4,t5,t6,t7 FROM alltable WHERE tablenamearray ='${tblname}' and tablecount ='${tblcount}'"$)
        End If
   
       
        Do While res.NextRow
               
            Dim tablecount As String = res.GetString(res.GetColumnName(2))
       
            If (tablecount = "5") Then '8-3 'And res.GetColumnName(6) <> ""
                Dim row(6) As String 'Object res.ColumnCount
           
                row(0) = res.GetInt(res.GetColumnName(0))'id
                row(1) = res.GetString(res.GetColumnName(3))'tablename
                row(2) = res.GetString(res.GetColumnName(4))'tablecount
                row(3) = res.GetString(res.GetColumnName(5))
                row(4) = res.GetString(res.GetColumnName(6))
                row(5) = res.GetString(res.GetColumnName(7))
               

            End If
       
            If (tablecount = "6" ) Then '8-3 'And res.GetColumnName(6) <> ""
                Dim row(7) As String 'Object res.ColumnCount
           
                row(0) = res.GetInt(res.GetColumnName(0))'id
                row(1) = res.GetString(res.GetColumnName(3))'tablename
                row(2) = res.GetString(res.GetColumnName(4))'tablecount
                row(3) = res.GetString(res.GetColumnName(5))
                row(4) = res.GetString(res.GetColumnName(6))
                row(5) = res.GetString(res.GetColumnName(7))
                row(6) = res.GetString(res.GetColumnName(8))
            End If
       
            If (tablecount = "7" ) Then '8-3 ' And res.GetColumnName(j) <> Null
                Dim row(8) As String 'Object res.ColumnCount
           
                row(0) = res.GetInt(res.GetColumnName(0))'id
                row(1) = res.GetString(res.GetColumnName(3))'tablename
                row(2) = res.GetString(res.GetColumnName(4))'tablecount
                row(3) = res.GetString(res.GetColumnName(5))
                row(4) = res.GetString(res.GetColumnName(6))
                row(5) = res.GetString(res.GetColumnName(7))
                row(6) = res.GetString(res.GetColumnName(8))
                row(7) = res.GetString(res.GetColumnName(9))
       
            End If
       
           
        Loop
   
        B4XTable1.SetData(Data)
       
    Catch
        Log("Error=" & LastException.Message)
    End Try
End Sub


Now, i tried calling the sub multiple times into pnl1, pnl2,.... thus:

b4xtable(Pnl1,4,0,"tbl1x","5")

b4xtable(Pnl2, 2, 1,"tbl2x","7")

...... ........
...... .......

Calling only works at one instance, but fails at multiple calls. Please help me with correct resumable or help me with another code that can achieve same result multiple times. The layout ("B4XT") is just empty b4xtable in the designer
 
Last edited:

b4x-de

Active Member
Licensed User
Longtime User
What exactly happens when it fails. Is there any error message or any exception? Could you please provide more information on this.
 
Upvote 0

omo

Active Member
Licensed User
Longtime User
What exactly happens when it fails. Is there any error message or any exception? Could you please provide more information on this.
Thanks, @b4x-de. As I said, it works if calls only once, but if I tried to make it resumable and called it multiple times, it threw errors of b4xview not initialized, I checked all the controls to identify if really one b4xview is not initialized. Unfortunately, I couldn't trace exact b4xview not initialized. Although, I don't know wheather that b4xview uninitialized is just false alert or not. Here is the log I caught when I directed the output logs to my email:

Error log:
--------- beginning of main
--------- beginning of system
~i:*** Service (starter) Create ***
~i:** Service (starter) Start **
~i:** Activity (main) Create (first time) **
~l1968747267:*** mainpage: B4XPage_Created
~l2968747267:*** mainpage: B4XPage_Appear
~i:** Activity (main) Resume **
~l3968747267:*** pmenus1: B4XPage_Created [mainpage]
~l4968747267:*** mainpage: B4XPage_Disappear [mainpage]
~l5968747267:*** pmenus1: B4XPage_Appear [mainpage]
~l6968747267:*** pmenufirst1: B4XPage_Created [pmenus1]
~l7968747267:*** pmenus1: B4XPage_Disappear [pmenus1]
~l8968747267:*** pmenufirst1: B4XPage_Appear [pmenus1]
~l9968747267:*** pexamreg21: B4XPage_Created [pmenus1, pmenufirst1]
~l0968747267:*** pmenufirst1: B4XPage_Disappear [pmenus1, pmenufirst1]
~l1968747267:*** pexamreg21: B4XPage_Appear [pmenus1, pmenufirst1]
~l2968747267:*** pexamtheorypq21: B4XPage_Created [pmenus1, pmenufirst1, pexamreg21]
~l3968747267:*** pexamreg21: B4XPage_Disappear [pmenus1, pmenufirst1, pexamreg21]
~l4968747267:*** pexamtheorypq21: B4XPage_Appear [pmenus1, pmenufirst1, pexamreg21]
~L5974121219~-65536:Error (position - 304): Invalid color value: -65536
~l6987097354:Target is not in the views tree!
~l7987097354:Target is not in the views tree!
~l8987097354:Target is not in the views tree!
~l9987097354:Target is not in the views tree!
~l0987097354:Target is not in the views tree!
~l1987097354:Target is not in the views tree!
~l2968747267:*** panswertheory21: B4XPage_Created [pmenus1, pmenufirst1, pexamreg21, pexamtheorypq21]
~l3968747267:*** pexamtheorypq21: B4XPage_Disappear [pmenus1, pmenufirst1, pexamreg21, pexamtheorypq21]
~l4968747267:*** panswertheory21: B4XPage_Appear [pmenus1, pmenufirst1, pexamreg21, pexamtheorypq21]
~e:answertheory2$ResumableSub_queansresume (java line: 22340)
~e:java.lang.RuntimeException: Object should first be initialized (B4XView).
~e: at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:67)
~e: at anywheresoftware.b4a.objects.B4XViewWrapper.asViewWrapper(B4XViewWrapper.java:91)
~e: at anywheresoftware.b4a.objects.B4XViewWrapper.setVisible(B4XViewWrapper.java:117)
~e: at b4a.waecpq22.answertheory2$ResumableSub_queans.resume(answertheory2.java:22340)
~e: at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:275)
~e: at anywheresoftware.b4a.BA.raiseEvent2(BA.java:215)
~e: at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
~e: at anywheresoftware.b4a.keywords.Common$15.run(Common.java:1804)
~e: at android.os.Handler.handleCallback(Handler.java:873)
~e: at android.os.Handler.dispatchMessage(Handler.java:99)
~e: at android.os.Looper.loop(Looper.java:193)
~e: at android.app.ActivityThread.main(ActivityThread.java:6953)
~e: at java.lang.reflect.Method.invoke(Native Method)
~e: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:593)
~e: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
java.lang.RuntimeException: Object should first be initialized (B4XView).
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:67)
at anywheresoftware.b4a.objects.B4XViewWrapper.asViewWrapper(B4XViewWrapper.java:91)
at anywheresoftware.b4a.objects.B4XViewWrapper.setVisible(B4XViewWrapper.java:117)
at b4a.waecpq22.answertheory2$ResumableSub_queans.resume(answertheory2.java:22340)
at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:275)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:215)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
at anywheresoftware.b4a.keywords.Common$15.run(Common.java:1804)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6953)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:593)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

I am not really sure if that error is really responsible and I can't even trace that b4xview that is not initialized. I tried to see if I can write code to track that uninitialized b4xview control or programmatically initialize it, but was unsuccessful. Is like I am not getting the resumable sub and call right. I have tried several trial and error resumable tricks but to no avail
 
Upvote 0

omo

Active Member
Licensed User
Longtime User
It's always good to upload a project that shows the error so someone can help you.
See if the example I attached works for you.
@Mariano Ismael Castro, thank you so much for your attempt to help and sorry for my late response. Aside from being my busy Sunday, i tried to exhaust all options on your code before i could get something to report back. I ran your program and exhasted all options trying to make it solve my problem but to no avail. I like your code simplicity and how you helped me reduce bulky code. However, i couldn't get that your code to work, but i gained insight from your approach. Thank you.

Now, i reverted your code back to my bulky approach and i added simple sql database for clearity purpose. Now, is giving better hope because this sample runs on one panel and root, but not yet on multiple panel. Here attached is your modified sample attached with database to make it easier to work with.
 

Attachments

  • TestResumable2nd.zip
    18 KB · Views: 83
Upvote 0

Mariano Ismael Castro

Active Member
Licensed User
@Mariano Ismael Castro, thank you so much for your attempt to help and sorry for my late response. Aside from being my busy Sunday, i tried to exhaust all options on your code before i could get something to report back. I ran your program and exhasted all options trying to make it solve my problem but to no avail. I like your code simplicity and how you helped me reduce bulky code. However, i couldn't get that your code to work, but i gained insight from your approach. Thank you.

Now, i reverted your code back to my bulky approach and i added simple sql database for clearity purpose. Now, is giving better hope because this sample runs on one panel and root, but not yet on multiple panel. Here attached is your modified sample attached with database to make it easier to work with.
1714355585634.png


One question, is this what you need?
 
Upvote 0

omo

Active Member
Licensed User
Longtime User
View attachment 153210

One question, is this what you need?
Not exactly what I need, but i am getting closer to it. I only worked on the last code you sent to ensure it works first. This one now works directly on activity/root page and in one panel that I placed in the designer. What I want now in this code is to demostrate if it can display b4xtable on multiple panels like i.e pnl1 pnl2, pnl3... at the same time. I have not been able to achieve that yet. After achieving that then I will try it in my main program to troubleshoot the errors I earlier posted.

In summary, at moment with that latest code, help me display b4xtable on mutiple 5- panels maybe on another activity/b4xpage with that resumable sub so I can confirm if the resumable works well on multiple panels before I move further in correcting my main program error. Thanks
 
Upvote 0

Mariano Ismael Castro

Active Member
Licensed User
Well, I'm sending you these changes I made, I'm not sure I've helped you with what you need. Maybe someone else can help you if this doesn't work for you.
 

Attachments

  • TestResumable2.zip
    18.9 KB · Views: 83
Upvote 0

omo

Active Member
Licensed User
Longtime User
Well, I'm sending you these changes I made, I'm not sure I've helped you with what you need. Maybe someone else can help you if this doesn't work for you.
Thank you so much for your time @Mariano Ismael Castro, I really appreciate your great effort. I tried this last one, but it didn't even run on my Android 14. I saw two layout statements, but only one designer in that code. I ran it as it is and later then added another layout, but to no avail.

Although, you may not need to rewrite that. With that last modification I sent, I can agree that the resumable works, but when I integrated it in my main code. The initialized b4xbview log error I earlier posted still persist which means resumable might not be responsible for that error.

I will raise another question later to see if it is possible to detect uninitialized variable programmatically or if every uninitialized control can detect controls and initialize them programmatically. I will also include my attempt.
Thank you so much once again,
Regards
 
Upvote 0

Mariano Ismael Castro

Active Member
Licensed User
Thank you so much for your time @Mariano Ismael Castro, I really appreciate your great effort. I tried this last one, but it didn't even run on my Android 14. I saw two layout statements, but only one designer in that code. I ran it as it is and later then added another layout, but to no avail.

Although, you may not need to rewrite that. With that last modification I sent, I can agree that the resumable works, but when I integrated it in my main code. The initialized b4xbview log error I earlier posted still persist which means resumable might not be responsible for that error.

I will raise another question later to see if it is possible to detect uninitialized variable programmatically or if every uninitialized control can detect controls and initialize them programmatically. I will also include my attempt.
Thank you so much once again,
Regards
Hey, sorry. I am doing the tests with B4J, I suggest that you do the same and if that is what you need, it is done for B4A
 
Upvote 0

omo

Active Member
Licensed User
Longtime User
Hey, sorry. I am doing the tests with B4J, I suggest that you do the same and if that is what you need, it is done for B4A
I just tried running the B4j version, but is giving error too. Although, as I said in my last message, with your help; I have been able to confirm resumable I was looking as the problem was not the actual problem causing error in my main program.

Later ( not today), I will raise another question pertaining to same work in order to resolve the persistent error when I called the resumable more than one in my main program. It has been cleared that resumable is not the problem itself.

I really, really appreciate you for your time and insight you gave me till I confirmed resumable was not the cause as I was thinking before. I am quite satisfy with your help towards achieving that. Thank you so much
 
Upvote 0
Top