Android Question Problem with array of Panels

paolofi

Member
Licensed User
Longtime User
I tried to use Panels array to create panels grid but I receive an error when try to retrieve the tag id:

java.lang.RuntimeException: Object should first be initialized (Panel).

B4X:
Sub Globals
    Dim ImgPanel(12) As Panel
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Dim r As Int
    Dim c As Int
    Dim sx As Int
    Dim sxInc As Int
    Dim a As Int
    Dim aInc As Int
    r=0
    c=0

    For i = 0 To ImgPanel.Length - 1
        Dim p As Panel
        p.Initialize("ImgPanel")
        Activity.AddView(p, sx+(c*sxInc), a+(r*aInc), 130dip, 130dip) 'add the panel to the layout

        p.Tag=i
     
        ImgPanel(i)=p
     
        c=c+1

        If c>3 Then
            r=r+1
            c=0
        End If
    Next
End Sub

Sub ImgPanel_Click
    'Using Sender we find the panel that raised this event
    Dim p As Panel
    Dim Id As Int

    p = Sender
    Id=p.Tag '**** HERE I RECEIVE THE ERROR: java.lang.RuntimeException: Object should first be initialized (Panel).

End Sub

Some suggest?

Thanks in advance

Lenny
 
Top