Android Question Error while opening B4XTable view

Makumbi

Well-Known Member
Licensed User
Please help me out
the error comes at
B4X:
   B4XTable1.Clear

B4X:
#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim cursor1 As Cursor
    Type StateType (TextUp As String, TextDown As String, _
        IndexUp As Int, IndexDown As Int)
    Dim State As StateType 'This must be a process variable as it stores the state
    'and should not be released when the activity is destroyed.
   
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim txtUp, txtDown As EditText
    Private B4XTable1 As B4XTable
    'Private xui As XUI
    Dim data As List
    Dim StudentName As EditText
    Dim Account As EditText
    Dim Classr As EditText
    Dim Latestdata As RadioButton
    'Dim kname As String
    Dim spnFirstName As Spinner
    Dim Spinner1 As Spinner
    Dim ImageView1 As B4XView
    Private xui As XUI
End Sub

Sub ResetState
    'set the starting state
    State.TextUp = 1
   
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:

    Activity.LoadLayout("academicextract")
   
    Activity.Title="Extract Results"
txtUp.Initialize("txtUp")
txtDown.Initialize("txtDown")
Log(ResetState)
   
    'ProgressDialogShow2("Fetching data...", False)
    ShowTable
    'years
    'getterm

   
End Sub

Sub IsConnectedToInternet As Boolean
    Dim r As Reflector

    r.Target = r.GetContext
    r.Target = r.RunMethod2("getSystemService", "connectivity", "java.lang.String")
    r.Target = r.RunMethod("getActiveNetworkInfo")

    If r.Target <> Null Then
        Return r.RunMethod("isConnectedOrConnecting")
    End If

    Return False
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)
    Activity.Finish
End Sub

Sub ShowTable
    B4XTable1.Clear
    B4XTable1.AddColumn("Student Names", B4XTable1.COLUMN_TYPE_TEXT).Width=150dip
    B4XTable1.AddColumn("Class", B4XTable1.COLUMN_TYPE_TEXT).Width=70dip
    B4XTable1.AddColumn("Amount", B4XTable1.COLUMN_TYPE_TEXT)
    B4XTable1.AddColumn("Account", B4XTable1.COLUMN_TYPE_TEXT)
    Dim data As List
    data.Initialize
'    Dim rs As ResultSet = Starter.sql1.ExecQuery("SELECT DISTINCT Names,Class || Stream As CS,Account,Amount As Balance FROM Balances ORDER BY Names ASC;" )
    cursor1 = Starter.SQL1.ExecQuery("SELECT phone AS Phone,Sex FROM Register")
    If cursor1.RowCount > 0 Then
        cursor1.Position =0
        Dim Phonet As String
        Phonet = cursor1.Getstring("Phone")
           
    End If
    Dim rs As ResultSet  = Starter.SQL1.ExecQuery2("SELECT DISTINCT Names,Class || Stream As CS,Account,Amount As Balance FROM Balances WHERE Phone = ?", Array As String(Phonet))

    Do While rs.NextRow
        Dim row(4) As Object
   
        row(0) = rs.GetString("Names")
        row(1) = rs.GetString("CS")
        row(2) = rs.GetString("Balance")
        row(3) = rs.GetString("Account")
            data.Add(row)
    Loop
    rs.Close
    B4XTable1.SetData(data)
    'B4XTable1.VisibleColumns.RemoveAt(B4XTable1.VisibleColumns.IndexOf("Account"))
End Sub
B4X:
Category: Active
Froms: /Date(1578258000000)/
Tos: /Date(1581714000000)/
06/01/2020
06/01/2020
15/02/2020
15/02/2020
result: Good
** Activity (main) Pause, UserClosed = false **
** Activity (curveextracted) Create, isFirst = true **
Error occurred on line: 505 (B4XTable)
java.lang.RuntimeException: Object should first be initialized (B4XView).
    at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:50)
    at anywheresoftware.b4a.objects.B4XViewWrapper.asViewWrapper(B4XViewWrapper.java:70)
    at anywheresoftware.b4a.objects.B4XViewWrapper.getTag(B4XViewWrapper.java:557)
    at com.kccug.kabojjajuniorapp.b4xtable._setpagelabelstate(b4xtable.java:2092)
    at com.kccug.kabojjajuniorapp.b4xtable._clearnavigationstate(b4xtable.java:2041)
    at com.kccug.kabojjajuniorapp.b4xtable$ResumableSub_Clear.resume(b4xtable.java:644)
    at com.kccug.kabojjajuniorapp.b4xtable._clear(b4xtable.java:507)
    at com.kccug.kabojjajuniorapp.curveextracted._showtable(curveextracted.java:437)
    at com.kccug.kabojjajuniorapp.curveextracted._activity_create(curveextracted.java:408)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
 

Makumbi

Well-Known Member
Licensed User
It happens because you are calling Clear before the table is ready. Add Sleep(0) before you call ShowTable in Activity_Create.

i have done that but the error is still coming
i have done it here as you suggested
B4X:
#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    'Dim SQL1 As SQL
    Dim cursor1 As Cursor
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private B4XTable2 As B4XTable
    'Private xui As XUI
    Dim data As List
    Private btnAdd, btnEdit, btnFilter, btnSetFilter As Button
    Private lblSelectedItem As Label
'    Private Label1 As Label
    Private badger1 As Badger
    
End Sub

Sub Activity_Create(FirstTime As Boolean)

        Activity.LoadLayout("academics")
    Activity.Title="Provisional Marks"
    badger1.Initialize
    Sleep(10)
    ShowTable
    'cursor1 = Starter.SQL1.ExecQuery("SELECT Names FROM Academics")
'    If cursor1.RowCount > 0 Then
        'ShowTable
    '    Else
    '    sendacademics
        'If cursor1.RowCount > 0 Then
        'ShowTable
        'End If
    'End If
    
    'ShowTable
    Dim intCount As Int
    intCount = Starter.SQL1.ExecQuerySingleResult("SELECT count(Id) as Id FROM Eventsinfo WHERE Tcode NOT LIKE '%Read%';")
            
    If intCount > 0 Then
        Dim ms As Int = intCount
    Else
        Dim ms As Int = 0
    End If
    Log(ms)
    badger1.SetBadge(btnAdd, ms)
    Dim cs As CSBuilder
    cs.Initialize.Color(Colors.Red).Append("Upcoming Events :" & ms).PopAll
    lblSelectedItem.Text = cs
    'badger1.SetBadge(lblSelectedItem, badger1.GetBadge(lblSelectedItem) + cs)
    'badger1.SetBadge(Label1, badger1.GetBadge(Label1) + ms)
    'sendacademics
    'ShowTable
End Sub


Sub Activity_Resume
ShowTable
End Sub
Sub ShowTable
    'B4XTable1.Refresh
    'B4XTable2.Clear
    'B4XTable1.Clear
    'B4XTable1.ClearDataView
    B4XTable2.AddColumn("Student Names", B4XTable2.COLUMN_TYPE_TEXT).Width=150dip
    B4XTable2.AddColumn("Class", B4XTable2.COLUMN_TYPE_TEXT).Width=80dip
    B4XTable2.AddColumn("Subject", B4XTable2.COLUMN_TYPE_TEXT)
    B4XTable2.AddColumn("Score", B4XTable2.COLUMN_TYPE_TEXT).Width=80dip
    B4XTable2.AddColumn("Grade", B4XTable2.COLUMN_TYPE_TEXT).Width=80dip
    B4XTable2.AddColumn("Term", B4XTable2.COLUMN_TYPE_TEXT)
    Dim data As List
    data.Initialize

    'Dim rs As ResultSet = Starter.sql1.ExecQuery("SELECT DISTINCT Names,Class || Stream As CS,Subject,Total As Score,grade as Grade,Term,Years FROM Academics ORDER BY Names ASC;" )
    cursor1 = Starter.SQL1.ExecQuery("SELECT phone AS Phone,Sex FROM Register")
    If cursor1.RowCount > 0 Then
        cursor1.Position =0
        Dim Phonet As String
        Phonet = cursor1.Getstring("Phone")
            
    End If



    Starter.SQL1.ExecNonQuery("UPDATE Academics SET grade ='GR' WHERE grade=:Grade OR grade is null ")
    Dim rs As ResultSet  = Starter.SQL1.ExecQuery2("SELECT DISTINCT Names,Class || Stream As CS,Subject,Total As Score,grade as Grade,Term,Years FROM Academics WHERE Phone = ? ORDER BY Grade ASC, Total DESC;", Array As String(Phonet))
    
    
    'Dim rs As ResultSet  = Starter.SQL1.ExecQuery2("SELECT DISTINCT Names,Class || Stream As CS,Subject,Total As Score,grade as Grade,Term,Years FROM Academics")
    'Dim rs As ResultSet = Starter.sql1.ExecQuery("SELECT DISTINCT Names,Class || Stream As CS,Subject,Total As Score,grade as Grade,Term,Years FROM Academics ORDER BY Names ASC;" )
    'CASE WHEN grade =NULL THEN 'EMPTY' ELSE grade END
    Do While rs.NextRow
        Dim row(6) As Object
    
        row(0) = rs.GetString("Names")
        row(1) = rs.GetString("CS")
        row(2) = rs.GetString("Subject")
        row(3) = rs.GetString("Score")
        row(4) = rs.GetString("Grade")
        row(5) = rs.GetString("Term")
        data.Add(row)
    Loop
    rs.Close
    B4XTable2.SetData(data)
    'B4XTable1.Refresh

End Sub



Sub Activity_Pause (UserClosed As Boolean)
    Activity.Finish
End Sub
Sub btnSetFilter_Click
    'starts the Filter Activity
    StartActivity(FilterA)
End Sub

Sub btnFilter_Click
    Starter.flagFilterActive = Not(Starter.flagFilterActive)
'    ShowTable
    
End Sub

Sub btnAdd_Click
    Activity.Finish
End Sub
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
i have done it here as you suggested
why you are calling showtable in activity_resume again? It was not the case in your code in #1
 
Upvote 0
Top