Android Question cursustekst.be B4A-List Tutorial | Null Pointer Exception

CosmicFlux

Member
Hello,

I've been following Paul's tutorials here https://cursustekst.be/index.php?t=2&o=5&c=121&p=114 and this line

B4X:
Private mnuitem As B4AMenuItem = B4XPages.AddMenuItem(objpage, itemname)

is throwing a null pointer error.

Full code here:

B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private catpage As CategoryPage
    Private subcatpage As SubcategoryPage
End Sub

Public Sub Initialize
'    B4XPages.GetManager.LogEvents = True
catpage.Initialize
subcatpage.Initialize
B4XPages.AddPage("Category", catpage)
B4XPages.AddPage("Subcategory", subcatpage)
menuitem_Add(Me, "Category")
menuitem_Add(Me, "Subcategory")
End Sub

Private Sub menuitem_Add(objpage As Object, itemname As String)
    Private mnuitem As B4AMenuItem = B4XPages.AddMenuItem(objpage, itemname) 'This throws exception
    mnuitem.AddToBar = True
End Sub

Sub B4XPage_MenuClick(Tag As String)
    B4XPages.ShowPage(Tag)
End Sub
'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
End Sub

Can't see where my code doesn't match Paul's, but it's giving me this:
1744297504457.png


Maybe I can't see the wood for the trees, or maybe things have changed since version 10 (what the tutorial is based on) but if anyone has any idead I would really appreciate the feedback.
 
Top