Android Question Losing global variable scope, when trying to access it in a timer - declared as array

mare1980k1

Member
Licensed User
Longtime User
Hi, I can't seem to figure this one out:

I have these players and timer in:
B4X:
Sub Process_Globals
Public PlayersArray(50) As SimpleExoPlayer
Public CstmTimerForPlay As Timer

The varible
B4X:
 PlayersArray(i)
is accessible in other subs, but not in CstmTimerForPlay_Tick, this is the second global variable I have the same problem with - the previous was array of ints. Normal global ints seem to be working fine. It seems that this behavior is only for arrays?

The array itself is declared, but doesn't have any values - isn't even initialized in the case of maps.

I do this:
B4X:
CstmTimerForPlay.Initialize("CstmTimerForPlay",100)
CstmTimerForPlay.Enabled = True

And then when I try
B4X:
 PlayersArray(i).Play
in CstmTimerForPlay_Tick it gives an error:

main_cstmtimerforplay_tick (java line: 987)
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.Object.equals(java.lang.Object)' on a null object reference
at com.promoTV.main._cstmtimerforplay_tick(main.java:987)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
at anywheresoftware.b4a.objects.Timer$TickTack.run(Timer.java:105)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

The players work fine and play well when I play it from any other sub, using the same number #i with that value that doesn't work in the timer - I checked.

Please help, thank you,
Kind regards,
Marko
 

agraham

Expert
Licensed User
Longtime User
Upvote 0

mare1980k1

Member
Licensed User
Longtime User
int "i" is not global, but local for both different subs, but I give the i to the timer, via some other methods, it is not the same int "i" just the same numeric value.

Thank you for your reply,
Marko
 
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
It seems likely that you are not actually doing what you think that you are doing. This sentence from post #1 -
The players work fine and play well when I play it from any other sub, using the same number #i with that value that doesn't work in the timer
... and this one from post #5 ...
I give the i to the timer, via some other methods, it is not the same int "i" just the same numeric value.
... are an example : That is what you think you are doing, but is it what you are actually doing?

Why don't you take Erel's advice in post #2?
 
Upvote 0

mare1980k1

Member
Licensed User
Longtime User
In the end I didn't solve the problem, so I really don't know where the mistake was. I just changed it completely and now it works. I transformed those global variables to local and it works without problems. Thank you!
 
Upvote 0
Top