Android Question storing panel objects in classes

sorex

Expert
Licensed User
Longtime User
Hello,

I'm trying out some class coding again and bumped into something I can't seem to solve and would like to have an explanation or solution on the behaviour.

I had it working by "posting" the panel name to the init & subs of the class.

But when trying to cut down the code a bit and using less sub calling variable I thought about sending the panel name in the init once and store it somewhere but I can't get it to work right.

the minified code looks like this...

B4X:
Sub Class_Globals
Dim mainactivity As Activity
Dim menupanel As Panel
End Sub

Sub Initialize(act As Activity,menu_panel As Panel)
mainactivity=act
menupanel=menu_panel
End Sub

Sub start()
menupanel.Visible=False
end sub

I get errors that menupanel is not initialized.

If I init it the error is gone but the panel is still visible, so I guess it created a new one and hides that?
 

DonManfred

Expert
Licensed User
Longtime User
You should initialize the panel before you initialize your class so the object you give as parameter should be initialized at this moment...
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
thanks to TDS for the hint on Activity.LoadLayout() , it was placed under the class init's :)
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
Manfred: another issue...

I use a call to another class

B4X:
Sub startGame()
Log("start game")
Dim game As GameClass
game.start()
End Sub

which gets executed to the point that I call the panel storage variable where I get a null pointer error while the panel storage variables are set in both classes during the init.

B4X:
Sub start()
Log("game started")
menupanel.Visible=False   <- null pointer happends here
gamepanel.Visible=True
End Sub
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
ok, it seems that I start seeing how these classes are (supposed to) working with each other.

I had to add a

B4X:
game.Initialize(mainactivity,menupanel,gamepanel)

right after the dim game, which makes sense (now) since you pass the values to a new class object.
 
Upvote 0
Top