I can't find the mistake.. please help. The program crashes on this simple example and I can't find what is wrong.
B4X:
Sub Process_Globals
Type anInt (x As Int)
End Sub
Sub Globals
Private Button1 As Button
Dim arrayofints() As anInt
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("Layout1")
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Button1_Click
arrayofints(0).x=150
ToastMessageShow(arrayofints(0).x, False)
End Sub
- Start with posting the full error message.
- Your arrayofints needs a size
- Additionally the array needs to be initialized (including all emelemts in it)
you need to initialize a type before you can use it.
try this (not tested)
B4X:
Sub Process_Globals
Type anInt (x As Int)
End Sub
Sub Globals
Private Button1 As Button
Dim arrayofints(1) As anInt
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("Layout1")
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Button1_Click
arrayofints(0).initialize
arrayofints(0).x=150
ToastMessageShow(arrayofints(0).x, False)
End Sub
yes, the errors are 2, the number of elements in the array has not been declared and the variable (array element) of custom type (object) has not been initialized.