B4J Question Strange Error: Not on FX application thread

Midimaster

Active Member
Licensed User
I move my app from B4A to B4J and it is the first time I use B4J.

I have two modules Main and Player.Bas and in my opinion I do nothing with multi-threading. I divided the code in this two modules to get a clear separation between UI-related code and pure data processing.

Therefore I often I call functions, which are in Player, from Main. Sometimes I call functions, which are in Main from Player

Now I have two harmless looking functions which cause an error in Release Mode. (In Debug mode it seems to work)

The calling function is in Player.Bas:
B4X:
Sub ImportHeader(Header() As Short) As String
...
     Main.SetzeSongTitelLabel(BAS.ReadNameFromHeader(50,20,Header))
...

And this is in Main:
B4X:
public Sub SetzeSongTitelLabel(NeuerTitel As String )
    Log("setze songname=" & NeuerTitel)
    SongNameLabel.Text= NeuerTitel
    Log("NEU=" & SongNameLabel.Text )
End Sub

The SetztSongTitelLabel is working as expected, when I call it from Main directly


And even stranger... If I divide the calling function into two lines...
B4X:
Sub ImportHeader(Header() As Short) As String
...
    Dim a As String=BAS.ReadNameausHeader(50,20,value)
    Main.SetzeSongTitelLabel(a)
...
... I get no error message but this loggging:
setze songname=BlueChampagne
NEU=BlueChampagne


.In both cases the Label Text does not change on the app.
 
Last edited:

Midimaster

Active Member
Licensed User
Oh thank you. This means that the bug is much earlier before this. I really use a library to unzip the file, which contains the header: ArchiverPlusZip. The only difference betwenn B4A version and B4J version seems to be, that I have to define
B4X:
    Zip.ZipExecutionMode = Zip.ZIP_EXECMODE_ASYNCHRONOUS

Because of this behavior I tried to wait for the Event ZipEvent_ZipResult in my calling function
B4X:
Public Sub LoadSong(file As String )
    file=DeZip(file,"")
    Log("B time point " & (DateTime.Now-GlobalZeit))
    Wait For ZipEvent_ZipResult(Result As Int, ErrorMsg As String)
    Log("C time point " & (DateTime.Now-GlobalZeit))
...

Sub DeZip(file As String) As String
    GlobalZeit=DateTime.Now
    Log("Zip START ")
    Zip.ZipExecutionMode = Zip.ZIP_EXECMODE_ASYNCHRONOUS
    Zip.DecryptZipWithString(ZipPasswort)
    Dim ZipFile As String = File.Combine( DataFolder, file)
    Dim lstEntries As List = Zip.ListZipEntries(ZipFile)
    Dim ZipInfo As ArchiverZipInfo = lstEntries.Get(0)
    Dim SourceDatei=ZipInfo.FileName
    Zip.UnZipFile2(ZipFile,SourceDatei,DataFolder,SourceDatei,"ZipEvent")
    Log("A time point" & (DateTime.Now-lZeit ))
    Return SourceDatei
End Sub


Sub ZipEvent_ZipResult(Result As Int,Error As String )
    Log("Zip RESULT" & Result & " " & Error)
    Log("D time point D (finished)" & (DateTime.Now-GlobalZeit ))
End Sub

Sub ZipEvent_ZipProgression(Operation As Int, Filename As String, Percent As Float )
      '  Log("working " & Operation & " " & Percent & "%")
End Sub

The time points "A" "B" are logged very fast and after a long time the time point "C" loggs too. (The time point D never loggs.)

I thought this reaching of time point "F" means that the process has finished. But if I use the code like this I get this problems in setting the Label.Text

Without Dezipping I receive no error messages.

Is my use of the Wait For wrong?
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…