B4J Question Initialize array of imageviews

ThRuST

Well-Known Member
Licensed User
Longtime User
Hello I have this code which generates an error at initialization. This is the class Icons

How to initialize the first image object (0)?

Main
B4X:
#Region Project Attributes
    #MainFormWidth: 600
    #MainFormHeight: 600
#End Region

Sub Process_Globals
 
    Private fx As JFX
    Public MainForm As Form
    Private Icons As Icons
 
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
    MainForm.Show
    
    Icons.Initialize
    Icons.CreateIcon
 
 
End Sub

'Return true to allow the default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
    Return True
End Sub

Class Icons
B4X:
Sub Class_Globals
    Private fx As JFX
    Private IconHeight, IconWidth As Int = 40
    Private IconLeft, IconTop As Int = 100
    Private xIcon() As ImageView
 
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
 
End Sub

public Sub CreateIcon
 
    xIcon(0).Initialize("")
    xIcon(0).Left = 100
    xIcon(0).Top = 100
    xIcon(0).Height = IconHeight
    xIcon(0).Width = IconWidth
 
    Main.MainForm.RootPane.AddNode(xIcon(0), 100,100,40,40)
    xIcon(0).SetImage(fx.LoadImage(File.DirAssets,"img.png"))
    xIcon(0).Visible = True
 
End Sub

Log

upload_2018-11-18_23-40-34-png.74491
 
Last edited:

ThRuST

Well-Known Member
Licensed User
Longtime User
Well since dynamic arrays didn't work the way I taught this did it

B4X:
Dim xIcon(10) As ImageView

instead of

B4X:
Private xIcon() As ImageView
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
Also, it's never a good idea to name an object the same as the class itself!
 
Upvote 0
Top