Android Question Using tablev2_17

afields

Member
Licensed User
Hello to all!
i would like to use tablev2_17.
however i've got those errors:
1) without custom view, with this code:
B4X:
Sub Globals
   Private Table2 As Table
   
End Sub
Sub Activity_Create(FirstTime As Boolean)
    Private lista_cabec As List
    Activity.LoadLayout("Main")
    lista_cabec.Initialize
    lista_cabec.Add("Uma")
    lista_cabec.Add("Duas")
    lista_cabec.Add("Três")
    Table2.Initialize(Me, "Table2")
    Table2.HeaderAlignment= Bit.Or(Gravity.CENTER_HORIZONTAL, Gravity.CENTER_VERTICAL)
    Table2.InitializeTable(3,Gravity.LEFT,False)
    Table2.RowHeight=30dip
   
    Table2.HeaderNames=lista_cabec
    Table2.AddRow(Array As String("1","João Manuel","30"))
   
   
    Table2.AddToActivity(Activity,10dip,10dip,300dip,400dip)
   
   
End Sub
i've got:
B4X:
Error occurred on line: 511 (Table)
java.lang.RuntimeException: Object should first be initialized (ScrollView2D).
    at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:50)
    at flm.b4a.scrollview2d.ScrollView2DWrapper.getPanel(SourceFile:65)
    at b4a.TableDemo216.table._innerclearall(table.java:1352)
    at b4a.TableDemo216.table._initializetable(table.java:207)
    at b4a.TableDemo216.main._activity_create(main.java:404)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:710)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:342)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
    at b4a.TableDemo216.main.afterFirstLayout(main.java:102)
    at b4a.TableDemo216.main.access$000(main.java:17)
    at b4a.TableDemo216.main$WaitForLayout.run(main.java:80)
    at android.os.Handler.handleCallback(Handler.java:815)
    at android.os.Handler.dispatchMessage(Handler.java:104)
    at android.os.Looper.loop(Looper.java:207)
    at android.app.ActivityThread.main(ActivityThread.java:5728)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)
** Activity (main) Resume **
and with a table's custom view ( with this code):
B4X:
Sub Activity_Create(FirstTime As Boolean)
    Private lista_cabec As List
    Activity.LoadLayout("Main")
    lista_cabec.Initialize
    lista_cabec.Add("Uma")
    lista_cabec.Add("Duas")
    lista_cabec.Add("Três")
    Table2.HeaderAlignment= Bit.Or(Gravity.CENTER_HORIZONTAL, Gravity.CENTER_VERTICAL)
    Table2.RowHeight=30dip
   
    Table2.HeaderNames=lista_cabec
    Table2.AddRow(Array As String("1","João Manuel","30"))
   
   
    Table2.AddToActivity(Activity,10dip,10dip,300dip,400dip)
   
   
End Sub
i've got that error:
B4X:
Error occurred on line: 1634 (Table)
java.lang.ArrayIndexOutOfBoundsException: length=0; index=0
    at b4a.TableDemo216.table._setheaderalignment(table.java:146)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:710)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:339)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
    at b4a.TableDemo216.main.afterFirstLayout(main.java:102)
    at b4a.TableDemo216.main.access$000(main.java:17)
    at b4a.TableDemo216.main$WaitForLayout.run(main.java:80)
    at android.os.Handler.handleCallback(Handler.java:815)
    at android.os.Handler.dispatchMessage(Handler.java:104)
    at android.os.Looper.loop(Looper.java:207)
    at android.app.ActivityThread.main(ActivityThread.java:5728)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)
** Activity (main) Resume **
however using methods like LoadTableFromCSV2 and the other from the database it works.
am i doing something wrong?
 

klaus

Expert
Licensed User
Longtime User
You should use Table class version 2.18, I amended an error in the setHeaderAlignment routine.
And change your Activity_Create routine like this:
B4X:
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Main")

    Table2.Initialize(Me, "Table2")
    Table2.AddToActivity(Activity,10dip,10dip,300dip,400dip)
    Table2.InitializeTable(3,Gravity.LEFT,False)
    Table2.RowHeight=30dip
  
    Table2.SetHeader(Array As String("Uma", "Duas", "Três"))
    Table2.HeaderAlignment= Bit.Or(Gravity.CENTER_HORIZONTAL, Gravity.CENTER_VERTICAL)
    Table2.AddRow(Array As String("1","João Manuel","30"))
 
End Sub
 
Upvote 0

afields

Member
Licensed User
As usual thank you very much Klaus.
I'll try the solution soon. I have a student book to finish for 5 months and other projects related to students and school.
Thanks again Klaus
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…