B4J Question [ABMaterial] (solved) ABMTable change and refresh

giannimaione

Well-Known Member
Licensed User
Longtime User
how to refresh ABMTable ?
code ConnectPage()
B4X:
   Dim nPAGE as int=1
   Dim tbl1 As ABMTable
   tbl1=custom.makeTable (nPAGE)
   page.Cell(2,1).AddComponent(tbl1)

in Sub pagination_PageChanged(OldPage As Int, NewPage As Int)
B4X:
   Dim pagination As ABMPagination = page.Component("pagination")
   pagination.SetActivePage(NewPage) ' IMPORTANT!
   pagination.Refresh
   '
   Dim tbl As ABMTable = page.Cell(2,1).Component("tbl1")
   tbl=custom.makeTable (NewPage)
   tbl.Refresh :' here crash ... see log error!

code Class custom
B4X:
Sub MakeTable (nPage As Int) As ABMTable
   Dim tbl1 As ABMTable
   tbl1.Initialize(page,"tbl1",True,False,True,"")
   tbl1.Clear
   tbl1.SetHeaders(Array As String("Cognome", "Nome"))
   tbl1.SetColumnDataFields(Array As String("Cognome", "Nome"))
   'here sql select from my database
   ' .....
   ' ......
   Do While rec.NextRow
       ' here making a table
       Dim r As List
       Dim rCellThemes As List
       r.Initialize
       rCellThemes.Initialize
       r.Add(cognome)
       rCellThemes.Add("nocolor") ' nocoloredit
       r.Add(nome)
       rCellThemes.Add("nocolor")
       tbl1.AddRow(idcliente, r) :' idcliente
       tbl1.SetRowThemes(rCellThemes) ' make sure you have as many items in rCellThemes as in r!
   Loop
   'close ResultSet and SQL
   rec.Close
   sql.Close
   Return tbl1
End Sub

error log when pagination_PageChanged
B4X:
java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.NullPointerException
   at anywheresoftware.b4a.BA.raiseEvent2(BA.java:119)
   at anywheresoftware.b4a.BA.raiseEvent(BA.java:77)
   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.b4j.object.WebSocketModule$Adapter$ThreadHandler.run(WebSocketModule.java:191)
   at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
   at java.util.concurrent.FutureTask.run(FutureTask.java:266)
   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
   at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.NullPointerException
   at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:496)
   at anywheresoftware.b4a.keywords.Common.CallSubNew3(Common.java:450)
   at manuale.gm.com.tabella._page_parseevent(tabella.java:300)
   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:90)
   ... 10 more
Caused by: java.lang.RuntimeException: java.lang.NullPointerException
   at anywheresoftware.b4a.BA.raiseEvent2(BA.java:119)
   at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:487)
   ... 17 more
Caused by: java.lang.NullPointerException
   at com.ab.abmaterial.ABMTable.GetActiveTableRow(Unknown Source)
   at com.ab.abmaterial.ABMTable.GetActiveRow(Unknown Source)
   at com.ab.abmaterial.ABMTable.RefreshInternal(Unknown Source)
   at com.ab.abmaterial.ABMTable.Refresh(Unknown Source)
   at manuale.gm.com.tabella._pagination_pagechanged(tabella.java:350)
   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:90)
   ... 18 more
 

alwaysbusy

Expert
Licensed User
Longtime User
This cannot work because you make a new table every time in maketable:

B4X:
Dim tbl As ABMTable = page.Cell(2,1).Component("tbl1")
tbl=custom.makeTable (NewPage)
tbl.Refresh :' here crash ... see log error!

You must take the existing table, just clear it and then refill it with the new content:
B4X:
Sub pagination_PageChanged(OldPage As Int, NewPage As Int)
   Dim pagination As ABMPagination = page.Component("pagination")
   pagination.SetActivePage(NewPage) ' IMPORTANT!
   pagination.Refresh

   Dim tbl As ABMTable = page.Cell(2,1).Component("tbl1")
   tbl.Clear

   'here sql select from my database

   Do While rec.NextRow
       ' here making a table
       Dim r As List
       Dim rCellThemes As List
       r.Initialize
       rCellThemes.Initialize
       r.Add(cognome)
       rCellThemes.Add("nocolor") ' nocoloredit
       r.Add(nome)
       rCellThemes.Add("nocolor")
       tbl1.AddRow(idcliente, r) :' idcliente
       tbl1.SetRowThemes(rCellThemes) ' make sure you have as many items in rCellThemes as in r!
    Loop

    tbl.Refresh
End Sub

Check out the feedback app sample for the full code.
 
Upvote 0

giannimaione

Well-Known Member
Licensed User
Longtime User
ok, i solved
B4X:
'connectpage()
   Dim nPAGE as int=1
   Dim tbl1 As ABMTable
   tbl1.Initialize(page,"tbl1",True,False,True,"")
   tbl1=custom.makeTable (tbl1,nPAGE)
   page.Cell(2,1).AddComponent(tbl1)
Class custom
B4X:
Sub makeTable (tbl1 As ABMTable,nPage As Int) As ABMTable
'..................
'..................
Return tbl1
and
B4X:
Sub pagination_PageChanged(OldPage As Int, NewPage As Int)
Dim tbl As ABMTable = page.Cell(2,1).Component("tbl1")
   tbl=custom.makeTable (tbl,NewPage)
   tbl.Refresh :' yes! work very well
 
Upvote 0
Top