Within Globals (in Main) a Public Panel is defined. The Activity_Create Sub performs some initialisation that includes calling a Sub in a code module that uses this Panel (accessed via Main.pnlMain). I find that sometimes when trying to access Main.pnlMain I get a exception, and sometimes I don't. The code looks something like this (slightly edited to removed code that does not use pnlMain):
1) If you look at the screen image 'Main null' it can be seen that hovering on Main in debug mode reveals that Main is (apparently) null, but data is displayed for Main in the watch window and it can also be seen that the line with the breakpoint has been successfully stepped over.
2) In the image 'Exception' a null object reference has occurred.
Why does this happen? What am I missing? It seemed to me (although this is a bit subjective) that the null exception tended to occur more when the Initialise sub was called earlier the Activity_Create and when the phone's orientation changed.
Any thoughts or ideas appreciated!
B4X:
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Public pnlMain As Panel
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("MainLayout")
pnlMain.Width = Activity.Width
pnlMain.Height = Activity.Height
Base.Initialise
End Sub
Sub Initialise()
Dim myds As Rect
myds.Initialize(xpos, Main.pnlMain.Height - 10%y, xpos + 6%x, Main.pnlMain.Height)
End Sub
1) If you look at the screen image 'Main null' it can be seen that hovering on Main in debug mode reveals that Main is (apparently) null, but data is displayed for Main in the watch window and it can also be seen that the line with the breakpoint has been successfully stepped over.
2) In the image 'Exception' a null object reference has occurred.
Why does this happen? What am I missing? It seemed to me (although this is a bit subjective) that the null exception tended to occur more when the Initialise sub was called earlier the Activity_Create and when the phone's orientation changed.
Any thoughts or ideas appreciated!