I am populating a table from a List Array.
This works great.
BUT, when I try and reload the Table, I get the following error:
The app halts here:
In Table Module:
B4X:
Dim cursor1 As Cursor
Dim txt As String
Dim MySPList As List
MySPList.Initialize
Table1.ClearAll
MySPList.clear
txt = "SELECT [Group] AS StoreGROUP, [Store] AS STORE, [Line Total] AS LINETOTAL, [Total Sales] AS TOTALSALES, [Budget] AS BUDGET, [Last Year] AS LASTYEAR, [GP %] AS GP, [# Of Trans] AS NUMOFTRANS, [UPT] AS UPT, [AVT] AS AVT, [Ft Count] AS FOOTCOUNT, [My Price] AS MYPRICE FROM tableSP2"
cursor1=SQL1.ExecQuery(txt)
For i=0 To cursor1.RowCount-1
cursor1.Position=i
Dim MY_GROUP As String = cursor1.GetString("StoreGROUP")
Dim MY_STORE As String = cursor1.GetString("STORE")
Dim MY_UPT As String = cursor1.GetString("UPT")
Dim MY_AVT As String = cursor1.GetString("AVT")
Dim MY_MYPRICE As String = cursor1.GetDouble("MYPRICE")
Dim MY_NUMOFTRANS As String = cursor1.GetDouble("NUMOFTRANS")
Dim MY_BUDGET As String = cursor1.GetDouble("BUDGET")
Dim MY_TOTALSALES As String = NumberFormat2(cursor1.GetDouble("TOTALSALES"), 1,2, 2,True)
Dim MY_LASTYEAR As String =cursor1.GetDouble("LASTYEAR")
Dim MY_LINETOTAL As String = cursor1.GetDouble("LINETOTAL")
Dim MY_GP As String = NumberFormat2(cursor1.GetDouble("GP"), 1,2, 2,True)
' Dim MY_PCRATE As String = NumberFormat2(cursor1.GetDouble("PCRATE"), 1,2, 2,True)
Dim MY_FOOTCOUNT As String = cursor1.GetDouble("FOOTCOUNT")
Dim MY_BUDGETPercent As Double = (MY_LINETOTAL / MY_BUDGET) 'PWSaleDetailLineTotal / Budget
Dim MY_GROWTHPercent As Double
If MY_LASTYEAR = 0 Then
MY_GROWTHPercent = 0
End If
If MY_LASTYEAR > 0 Then
MY_GROWTHPercent = (MY_LINETOTAL / MY_LASTYEAR) -1
End If
MY_GROWTHPercent = NumberFormat2(MY_GROWTHPercent,1,4,4,True)
Dim MY_FcCONPercent As Double
If MY_FOOTCOUNT = 0 Then
MY_FcCONPercent = 0
End If
If MY_FcCONPercent > 0 Then
MY_FcCONPercent = (MY_NUMOFTRANS / MY_FOOTCOUNT)
End If
MY_FcCONPercent = NumberFormat2(MY_GROWTHPercent,1,4,4,True)
Dim MY_PRICEPercent As Double = (MY_MYPRICE / MY_LINETOTAL) 'MyPrice / PWSaleDetailLineTotal
MY_NUMOFTRANS = NumberFormat2(MY_NUMOFTRANS,1,2,0,True)
MY_LASTYEAR = NumberFormat2(MY_LASTYEAR,1,2,2,True)
MY_BUDGET = NumberFormat2(MY_BUDGET,1,2,2,True)
MY_BUDGETPercent = NumberFormat2(MY_BUDGETPercent,1,4,4,True)
MY_MYPRICE = NumberFormat2(MY_MYPRICE,1,4,4,True)
MY_PRICEPercent = NumberFormat2(MY_PRICEPercent,1,4,4,True)
MySPList.Add(MY_GROUP & MY_STORE & MY_TOTALSALES & MY_BUDGET & MY_BUDGETPercent & MY_LASTYEAR & MY_GROWTHPercent & MY_GP & MY_NUMOFTRANS & MY_UPT & MY_AVT & MY_FOOTCOUNT & MY_FcCONPercent & MY_MYPRICE & MY_PRICEPercent)
Dim tf() As Typeface
tf = Array As Typeface(Typeface.DEFAULT, Typeface.DEFAULT_BOLD, Typeface.DEFAULT, Typeface.DEFAULT_BOLD, Typeface.DEFAULT)
Table1.SetTypeFaces(tf)
Table1.SetHeader(Array As String("Group", "Store", "Total Sales", "Budget", "Budget %", "Last Year", "Growth %", "GP %", "# of Trans", "UPT", "AVT", "Ft Count", "Fc Con %", "My Price", "My Price %"))
Table1.SetColumnsWidths(Array As Int(25%x, 40%x, 25%x, 25%x, 20%x,25%x, 20%x, 15%x, 20%x, 25%x,25%x, 20%x, 20%x, 25%x, 25%x))
Table1.AddRow(Array As String(MY_GROUP, MY_STORE, MY_TOTALSALES, MY_BUDGET, MY_BUDGETPercent, MY_LASTYEAR, MY_GROWTHPercent, MY_GP, MY_NUMOFTRANS, MY_UPT, MY_AVT, MY_FOOTCOUNT, MY_FcCONPercent, MY_MYPRICE, MY_PRICEPercent))
Next
BUT, when I try and reload the Table, I get the following error:
B4X:
Error occurred on line: 597 (Table)
java.lang.ArrayIndexOutOfBoundsException: length=5; index=5
at b4a.example.table._createnewlabels(table.java:1832)
at b4a.example.table._innerclearall(table.java:1428)
at b4a.example.table._clearall(table.java:602)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:668)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:337)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:244)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:132)
at anywheresoftware.b4a.BA$3.run(BA.java:334)
at android.os.Handler.handleCallback(Handler.java:808)
at android.os.Handler.dispatchMessage(Handler.java:103)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5339)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:828)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:644)
at dalvik.system.NativeStart.main(Native Method)
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (main) Create, isFirst = false **
** Activity (main) Resume **
** Activity (main) Create, isFirst = false **
** Activity (main) Resume **
B4X:
L.Typeface = cTypeFaces(i)
B4X:
Private Sub CreateNewLabels As Label()
Dim lbls(NumberOfColumns) As Label
For i = 0 To NumberOfColumns - 1
Dim rc As RowCol
rc.Col = i
Dim L As Label
L.Initialize("Cell")
L.TextSize = cTextSize
If cUseColumnColors = False Then
L.TextColor = cTextColor
Else
L.TextColor = cTextColors(i)
End If
If MultiTypeFace = False Then
L.Typeface = cTypeFace
Else
L.Typeface = cTypeFaces(i)
End If
SetPadding(L, 4dip, 2dip, 4dip, 2dip)
' added by nir, make each label single line
If cSingleLine Then
Dim ref As Reflector
ref.Target = L
ref.RunMethod2("setSingleLine", True, "java.lang.boolean")
End If
L.Tag = rc
lbls(i) = L
Next
Return lbls
End Sub