Android Question Int array mistake, help

mare1980k1

Member
Licensed User
Longtime User
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
 

DonManfred

Expert
Licensed User
Longtime User
crashes on this simple example and I can't find what is wrong
- Start with posting the full error message.
- Your arrayofints needs a size
- Additionally the array needs to be initialized (including all emelemts in it)
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
you're confusing arrays with types.

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
 
Upvote 0
Top