Android Question B4A 7 Error: Can Wait For be used in a Class? [Resolved with Beta 2]

GuyBooth

Active Member
Licensed User
Longtime User
Having some peculiar errors when I use Wait For in a class.
The code snippet is
B4X:
            If TMM.gbClearTracksPrompt And Not(bOverRideClearTracksPrompt) _
                And    (TMM_FlipFlop.lstTracks.Size > 1) Then
                CallSub2(TMM_FlipFlop, "ConfirmAsync","Empty the Queue?")
                ' Wait for the Confirmation dialog to be completed
                Wait for ConfirmAsync_Complete
                ' The result has now been stored in mbxResult
                bFadeStopClearTracks = TMM_Run.mbxConfirm
            Else
                bFadeStopClearTracks = True
            End If
If I comment out the line "Wait For ConfirmAsync_Complete" the program compiles (but of course no longer works properly)
B4X:
Compiling generated Java code.    Error
B4A line: 302
TMM.LogSub(sCodeName)
javac 1.8.0_66
src\b4a\themusicmachine\clmultiplayer.java:209: error: non-static method getActivityBA() cannot be referenced from a static context
parent._vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv7._vvvvvvvvvvvvvvvvvvvvvvvvvvvvv2(getActivityBA(),_scodename);
                                                                                  ^
Another example - also using Wait For in a Class:
B4X:
Compiling generated Java code.    Error
B4A line: 641
TMM.LogSub($\
javac 1.8.0_66
src\b4a\themusicmachine\clupnpplayer.java:572: error: non-static method getActivityBA() cannot be referenced from a static context
parent._tmm._logsub(getActivityBA(),(""+parent.__c.SmartStringFormatter("",(Object)(_scodename))+" FadeMode is "+parent.__c.SmartStringFormatter("",(Object)(parent._fadestopfademode))+""));

But they're inconsistent - sometimes (not usually) it will compile just fine. No difference between Debug, Release and Release (obfuscated) modes.
The errors also appear to have nothing to do with the Wait For code that seems to trigger them.
Can anyone point to a probable cause? Is it possibly a compiler problem with V 7 beta?
 

GuyBooth

Active Member
Licensed User
Longtime User
I will need to take some time to find a small enough section to be useful to you (this is a pretty big project), but will try to do that later today.
In the meantime, some more info:
Commenting out the Wait For statement in the class allows the app to compile (as stated above)
Replacing the Wait For statement with Sleep(0) on line 317 produces another compiler error:
B4X:
B4A version: 7.00 BETA #1
Parsing code.    (0.27s)
Compiling code.    Error
Error compiling program.
Error description: Value cannot be null.
Parameter name: key
Occurred on line: 317
Sleep(0)
Word: (
(This is also reflected with error messages in the IDE - Value cannot be null, and Parameter name: key)
Might be useful information for figuring out what is happening.
 
Upvote 0

Adie

Member
Licensed User
Longtime User
Also my project 'never' reach JobDone if I use 'Wait For'

B4X:
' *************************************
Sub ExecuteRemoteQuery(Query As String, JobName As String)
    Dim job As HttpJob
    job.Initialize(JobName, Me)
    job.PostString("https://batchman.co.za/android/rserver.php", Query)
  
    Wait For JobDone( job As HttpJob ) <=== If I uncomment this it works fine else NEVER
  
End Sub

' *************************************
Sub JobDone(Job As HttpJob)
    ProgressDialogHide
    If Job.Success Then
        Select Job.JobName
            Case ReadCloud
' Some code

            Case WriteCloud
' Other code

        End Select      
    Else
        Log(Job.ErrorMessage)
        ToastMessageShow("Error: " & Job.ErrorMessage, True)
    End If
    Job.Release
End Sub

Adie
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
@Adie please always start a new thread for your posts. This has nothing to do with this thread.

You are not using Wait For correctly. The JobDone sub will not be executed because the code will continue after the Wait For call (and do nothing because there is no code there).

See this post: [B4X] OkHttpUtils2 with Wait For
 
Upvote 0

Adie

Member
Licensed User
Longtime User
THANKS Working now with this code.

WaitFor JobDone( job AsHttpJob )
JobDoneX(job) <============= Added

Renamed 'default' JobDone(.. to JobDoneX(...

Apology, thought the 'cause' was the same that why this thread.

The more I use B4A the more I LAAAIIIKKKK

Adie
 
Upvote 0
Top