Android Question [SOLVED] B4Xpages - null pointer exception

rosippc64a

Active Member
Licensed User
Longtime User
Hi All!
I should have been doing b4xpages a long time ago, but I have older big projects and when I pull out b4xpages, I run into silly things that make me feel really stupid. Here is this code:
B4X:
Sub Class_Globals
    Private Root As B4XView 'ignore
    Private xui As XUI 'ignore
    Private btnAutomataUrites As B4XView
    Private btngetTokenForAutomata As B4XView
    Private btngetTokenForMerchant As B4XView
    Private btnPoharEladas As B4XView
    Private btnPoharValtas As B4XView
    Private btnTCP As B4XView
    Private cl As CustomListView
    Dim cs As CSBuilder
    Private B4XComboBox1 As B4XComboBox
End Sub

'You can add more parameters here.
Public Sub Initialize As Object
    Return Me
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    'load the layout to Root
    Root.LoadLayout("SzervizPage")
    B4XPages.SetTitle(Me, "Szerviz")
    pageInit
End Sub

'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.
private Sub pageInit
    B4XComboBox1.cmbBox.Clear
    B4XComboBox1.cmbBox.Add("VÁLASSZ")
    For i = 1 To 10
        If i > 9 Then
            B4XComboBox1.cmbBox.Add($"REPOHAR000${i}"$)
        Else
            B4XComboBox1.cmbBox.Add($"REPOHAR0000${i}"$)
        End If
    Next
End Sub

Private Sub btngetTokenForMerchant_Click
    cl.Clear '<-- java.lang.NullPointerException: Attempt to invoke virtual method 'void anywheresoftware.b4a.objects.collections.List.Clear()' on a null object reference'
    ...
End Sub
All button and customlistview are in the layout, but when I click the btngetTokenForMerchant button, my app doesn't know the cl. Why? The Root.LoadLayout("SzervizPage") didn't initialize all view on the layout? What is the problem with it? When I check cl in pageInit, it is initialized well. Something I do not understand. One year ago, the last time I managed to make a multi-page b4xpages app, I ran into this oddity, but I don't know how I managed to solve it then.
thanks for the help
 

rosippc64a

Active Member
Licensed User
Longtime User
Your question helped me, when I get log(cl), I realized that there is a resume event and a message that said: Szervizpage already exists.
Finally the error wasn't there: I reinitialized the Szervizpage in the B4XMainPage. I was stupid really.
 
Last edited:
Upvote 0
Top