Android Question [ANSWERED] Custom View NullPointerException setting contained view properties

Lee Gillie CCP

Active Member
Licensed User
This is my first Custom View. The approach I'm taking is to add a class named SignatureWidget for which I have prescribed Initialize and DesignerCreateView. But apparently views my widget is composed of are not be instantiated?

I add a CustomView to my main display selecting SignatureWidget as the custom type.

'Class module
Sub Class_Globals
    Private mTarget As Object
    Private mEventName As String
    Private mlblTitle As Label
    Private mlblTitle2 As Label
    Private mlblTimestamp As Label
    Private mlblSignedBy As Label
    Private mSignatureImage As ImageView
    Private mSignatureBorder As Panel
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize( TargetModule As Object, EventName As String )
   mTarget = TargetModule
   mEventName = EventName
End Sub

Sub DesignerCreateView(Base As Panel, Lbl As Label, Props As Map)


      mlblTitle.Text = ""
      mlblTitle2.Text = ""
      mlblTimestamp.Text = ""
      mlblSignedBy.Text = ""

      mlblTitle.TextColor = Lbl.TextColor
      mlblTitle2.TextColor = Lbl.TextColor
      mlblTimestamp.TextColor = Lbl.TextColor
      mlblSignedBy.TextColor = Lbl.TextColor

    Base.AddView(mlblTitle2, Base.Width/2,0,Base.Width/2,50)
End Sub

Public Sub setTitle(Title As String)
  mlblTitle.Text = Title <-- NullPointerException
End Sub

Public Sub getTitle() As String
  Return mlblTitle.Text
End Sub

Public Sub setTitle2(Title2 As String)
  mlblTitle2.Text = Title2
End Sub

Public Sub getTitle2() As String
  Return mlblTitle2.Text
End Sub

Public Sub setSignedBy(SignedBy As String)
  mlblSignedBy.Text = SignedBy
End Sub

Public Sub getSignedBy() As String
  Return mlblSignedBy.Text
End Sub

Public Sub setTimestamp(Timestamp As String)
  mlblTimestamp.Text = Timestamp
End Sub

Public Sub getTimestamp() As String
  Return mlblTimestamp.Text
End Sub
This is my first try at a Custom View implemented as a B4A class, so sure I'm doing SOMETHING wrong, but sure don't see it from the very few other examples I see posted.

Lee Gillie CCP

Active Member
Licensed User
No, and as might be expected no crash. Would be awesome to be able to build the UI for the custom view in the designer, but from my research this needs to be constructed in code.

Is the DesignerCreateView supposed to be internally invoked at app run time?

Lee Gillie CCP

Active Member
Licensed User
I found the issue. Some confusion with the designer. I had been attempting to make a layout for the custom view in the designer, and ended up with a copy of my main view. When the original main view was loaded it had not contained the new custom view, and thus the null pointer exception. It was looking like a huge mystery late Friday, but this morning it is glaringly obvious.