B4J Question [ABMaterial] AddArrayComponent() issue

Harris

Expert
Licensed User
Longtime User
Prior to 320, this worked fine.
Now I get - Container No component found with id x2

B4X:
Sub btnpids_Clicked(Target As String)

    Dim pidbox As ABMModalSheet = page.ModalSheet("pidbox")
    Dim j As Int = 1
    Dim k As Int = 2
   
   Log("what is selected selpid: "&selpid)


    For i = 0 To pidmap.Size -1
        Dim id,disp As Int

        id = pidmap.GetKeyat(i)
       
        Dim user As Map
        user.Initialize
        user = pidmap.GetValueat( i )
        Dim nam As String
        Dim switch1 As ABMSwitch
        nam = user.Getkeyat(0)
       
         If selpid.ContainsKey(""&id) Then
            disp = 1
         Else
             disp = 0       
         End If
       
        If (disp = 0) Then           
            switch1.Initialize(page, "x"&id ,  nam,  "", False,  "")
           
        Else
            switch1.Initialize(page, "x"&id ,  nam,  "", True,  "")
        End If       
            switch1.Tag = disp
            pidbox.Content.Cell(k,j).RemoveAllComponents
            pidbox.Content.Cell(k,j).AddArrayComponent( switch1,  "pid")
            Log(" Building pids: x"&id) ' shows the correct ID that was added to array
            j = j + 1
            If j = 4 Then
                k = k + 1
                j = 1
            End If
    Next   
    page.ShowModalSheet("pidbox")
   
End Sub

Sub pid_Clicked(Target As String)

   Log(" what is target: "&Target) ' shows full target
  
   Dim pidbox As ABMModalSheet = page.ModalSheet("pidbox")
   Dim p As String
   Dim sz As Int = selpid.Size
   p = Target.Replace( "pidbox-content-pid","") ' strip junk from target to get the ID

   Dim switch1 As ABMSwitch = pidbox.Content.Component( p)

  
   Log("what is before component: "&p&"   id: "&switch1.ID&"   tag: "&switch1.Tag )

' blows up cause it can't find the ID of switch1
' Now I get -  Container No component found with id x2


   Log("what is before selpid: "&selpid)
   If (selpid.Size = 4) Then
'        Toast(" Only Four PIDs Allowed! ",5000)
        switch1.Tag = 1   
  End If
   If switch1.Tag = 1 Then
         switch1.State = False
      'switch1.Image = "../images/ostar.png"
      switch1.Tag = 0
   Else
         switch1.State = True
      'switch1.Image = "../images/star.png"
      switch1.Tag = 1
      
   End If         
   switch1.Refresh
  
   If switch1.Tag = 1 Then
      selpid.Put(p,1)
   Else
      selpid.Remove(p)
   End If
  
   If (sz = 4) And (selpid.Size = 4 ) Then
        Toast(" Only Four PIDs Allowed! ",5000)
'        switch1.Tag = 1   
  End If
  
   Log("what is component: "&p&"   id: "&switch1.ID&"   tag: "&switch1.Tag )
   Log("what is selpid: "&selpid)


   
End Sub
 

alwaysbusy

Expert
Licensed User
Longtime User
Would it be possible to post your logs (so I can see your log() calls)? A modalsheets .content is internally an ABMContainer, and as the ABMContainer has been rewritten, the returned Target in the events may be different (actually more correct) than the ones you are used to. I'm not sure if it is still in there, but when I wrote the changes, if a component was not found, there was also a debug in the logs that showed a list of the components which do exist too.

Don't worry, I'll help you through this :)
 
Upvote 0

Harris

Expert
Licensed User
Longtime User
Page Parse Event: ecmviewPage - (MyMap) {eventparams=target, eventname=pid_clicked, target=pidbox-content-pidx4}
what is target: pidbox-content-pidx4
Container No component found with id x4
Error occurred on line: 1731 (ecmviewPage)
java.lang.NullPointerException
at abmtripinspect.ti.com.ecmviewpage._pid_clicked(ecmviewpage.java:3415)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:612)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:229)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:159)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:90)
at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:462)
at anywheresoftware.b4a.keywords.Common.CallSubNew2(Common.java:417)
at abmtripinspect.ti.com.ecmviewpage._page_parseevent(ecmviewpage.java:3295)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:612)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:229)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:159)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:90)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:84)
at anywheresoftware.b4j.object.WebSocketModule$Adapter$1.run(WebSocketModule.java:126)
at anywheresoftware.b4a.keywords.SimpleMessageLoop.runMessageLoop(SimpleMessageLoop.java:30)
at anywheresoftware.b4a.StandardBA.startMessageLoop(StandardBA.java:26)
at anywheresoftware.b4a.ShellBA.startMessageLoop(ShellBA.java:111)
at anywheresoftware.b4a.keywords.Common.StartMessageLoop(Common.java:131)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:301)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:159)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:90)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:84)
at anywheresoftware.b4j.object.JServlet.createInstance(JServlet.java:65)
at anywheresoftware.b4j.object.BackgroundWorkersManager$1.run(BackgroundWorkersManager.java:21)
at anywheresoftware.b4a.keywords.SimpleMessageLoop.runMessageLoop(SimpleMessageLoop.java:30)
at anywheresoftware.b4a.StandardBA.startMessageLoop(StandardBA.java:26)
at anywheresoftware.b4a.ShellBA.startMessageLoop(ShellBA.java:111)
at anywheresoftware.b4a.keywords.Common.StartMessageLoop(Common.java:131)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:301)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:159)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:90)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:84)
at abmtripinspect.ti.com.main.main(main.java:29)
 
Upvote 0

Harris

Expert
Licensed User
Longtime User
I remember reading you rebuilt container so I went looking if I used a container in my sheet... but didn't find one.
Here is the build pid box sub.

B4X:
Sub BuildpidBox() As ABMModalSheet
    Dim msgbox As ABMModalSheet
    msgbox.Initialize(page, "pidbox",   True,  ABM.MODALSHEET_TYPE_NORMAL,"")
    msgbox.Size = ABM.MODALSHEET_SIZE_NORMAL
    msgbox.IsDismissible = False
   
    msgbox.Content.AddRowsM( 1, True, 0,20, "").AddCells12(1, "")
    msgbox.Content.AddRows( 8 , True, "").AddCellsOSMP(1,0,0,0,4,4,4,0,0,0,0,  "").AddCellsOSMP(1,0,0,0,4,4,4,0,0,0,0,  "").AddCellsOSMP(1,0,0,0,4,4,4,0,0,0,0,  "") '.AddCellsOSMP(1,0,0,0,3,3,3,0,0,0,0,  "")

    msgbox.Content.AddRows( 1 , True, "").AddCellsOSMP(4,0,0,0,3,3,3,0,0,0,0,  "") '.AddCellsOSMP(1,0,0,0,4,4,4,0,0,0,0,  "").AddCellsOSMP(1,0,0,0,3,3,3,0,0,0,0,  "") .AddCellsOSMP(1,0,0,0,3,3,3,0,0,0,0,  "")
   
    msgbox.Content.AddRowsM( 1, True, 0,10, "").AddCells12(1, "")
   
    msgbox.Content.BuildGrid
   
    ' add paragraph   
    msgbox.Content.Cell(1,1).AddComponent(ABMShared.BuildParagraphBQWithZDepth(page,"par1","Choose PID Items to Display  (Maximum 4 Items in Total)") )
   
    Dim flag1 As ABMInput
    flag1.Initialize(page,"flag1",ABM.INPUT_NUMBER,"PID Flag 1",False,"")
    flag1.Text = 0
    msgbox.Content.Cell(10,1).AddComponent(flag1)

    Dim flag2 As ABMInput
    flag2.Initialize(page,"flag2",ABM.INPUT_NUMBER,"PID Flag 2",False,"")
    flag2.Text = 0
    msgbox.Content.Cell(10,2).AddComponent(flag2)
   
    Dim flag3 As ABMInput
    flag3.Initialize(page,"flag3",ABM.INPUT_NUMBER,"PID Flag 3",False,"")
    flag3.Text = 0
    msgbox.Content.Cell(10,3).AddComponent(flag3)

    Dim flag4 As ABMInput
    flag4.Initialize(page,"flag4",ABM.INPUT_NUMBER,"PID Flag 4",False,"")
    flag4.Text = 0
    msgbox.Content.Cell(10,4).AddComponent(flag4)
   
   
   
    msgbox.Content.Cell(11,1).AddComponent(ABMShared.BuildParagraphBQWithZDepth(page,"par2","Select PIDs in the order you which them to appear in the legend. For example, turn all PIDs OFF. For RPM as first, select Engine Revs; for Speed as second, select ECM Speed, etc...") )
       
    msgbox.Footer.AddRowsM ( 1,False,0,0, "").AddCellsOS(1,0,0,0,6,6,6,"").AddCellsOS(1,0 ,0,0,6,6,6, "")
    msgbox.Footer.BuildGrid 'IMPORTANT once you loaded the complete grid AND before you start adding components

    Dim msgok As ABMButton
    msgok.InitializeFlat(page, "pidok", "mdi-navigation-check",  ABM.ICONALIGN_LEFT, "OK", "transparent")
    msgbox.Footer.Cell(1,1).AddComponent(msgok)
    Log(" in pidbox build")
   
    Return msgbox
End Sub
 
Upvote 0

Harris

Expert
Licensed User
Longtime User
Perhaps you wanted this?
 

Attachments

  • B4JAnalyse.zip
    247.7 KB · Views: 316
Upvote 0

alwaysbusy

Expert
Licensed User
Longtime User
it is probably as simple as replacing:

B4X:
p = Target.Replace( "pidbox-content-pid","")
with:
B4X:
p = Target.Replace( "pidbox-content-","")

which does make sense (and was wrong pre 3.20):

the component is called pidx2 (the 'pid' from .AddArrayComponent( switch1, "pid") and 'x2' its id (from switch1.Initialize(page, "x"&id , nam, "", False, ""). The prefix in target is the parent: pidbox-content-

if you would use switch1.Initialize(page, ""&id , nam, "", False, ""), (without the x), it would even be more elegant, as the arrayed switches would be then called pid1, pid2 etc...
 
Last edited:
Upvote 0

Harris

Expert
Licensed User
Longtime User
Yes, that works....
Now I will strip the "pid" from it in another var because I need the number - which comes from a table.
I should have seen that myself.....
Thanks
 
Upvote 0
Top