B4J Question Compiling error with AsyncStreamsObject

HARRY

Active Member
Licensed User
Longtime User
Hi,

I intend to use in a B4J program AsyncStreamsObject and added the AsyncStreamsObject.bas as module.

Furthermore the following lines of code were added:

B4X:
Dim CStream As  AsyncStreamsObject

CStream.Initialize(Me,"CStream")

CStream.WriteFile("Webcam","/home/pi/MyApps/Domo","Webcam.jpg")


At compilation time I get following error information:

B4J version 2.80
Parsing code. 0.03
Compiling code. 0.09
Compiling generated Java code. Error
B4J line: 108
value = fx.LoadImage(Dir, FileName)
javac 1.7.0_45
src\b4j\example\asyncstreamsobject.java:89: error: cannot access Image
_value = (Object)(_fx.LoadImage(_dir,_filename).getObject());
^
class file for javafx.scene.image.Image not found
1 error


What can be the reason?

Harry
 

HARRY

Active Member
Licensed User
Longtime User
Hi Erel,

It is a pity that AsyncStreamsObject requires a UI program.

Should I expect strange side effects if I transform the non-Ui program to a Ui program with one Activity which is loaded but is empty and not visible and no screen is attached to the raspberry? Of course I would then use AsyncStreamsObject!
Should I leave StartMessageLoop in that UI program?

Harry
 
Upvote 0

HARRY

Active Member
Licensed User
Longtime User
Thanks Erel, that is quite helpfull.

May I suggest that you add in the description of AsyncStreamsObject that it can be used in UI as well as in Non-UI programs. With the hint for the latter purpose.

Next another problem on the same topic:

In B4J I shell to fswebcam to make a photo from the webcam and put it into a file . After doing so fswebcam exits. Then I send that foto as file using AsyncStreamObject to my Samsung phone. This results into the following error message on the phone, where the receiving program is written in B4A :

An error occurred in sub:java.io.IOException: unknown format (magic number 9c78) Continu?

If continued:

An error has occurred in sub: java.lang NegativeArraySizeException:-2555937

When I move the file to my laptop it displays correctly. Strange is, for me, that the file size on the raspberry is 220.668 and on my laptop: 217932.

Any idea what is going wrong?

Harry
 
Upvote 0

HARRY

Active Member
Licensed User
Longtime User
No, the file does not arrive correctly. As far as I can trace , the error occurs in AsyncStreamsText.bas in

Private Sub astream_NewStream (Dir As String, FileName As String) on line :

waitingForKey = raf.ReadB4XObject(raf.CurrentPosition)

Before waitingForKey I have logged raf.size. Result: 46, whereas the image size is reported to be 88,099 by the server, just before .WriteFile

Using AsyncStreamsObject I have the following code:

B4X:
Dim Stream2 As AsyncStreamsObject
Dim Client2 As Socket

Client2.Initialize("Client2")

If wifi.IsWifiConnected= True AND wifi.getSSID="JetStream" Then
        Local=True
        Client2.Connect("192.168.2.5",8400, 20000)      
    Else
        Local=False
        Client2.Connect("my ip addr",8400,20000)
    End If  

Sub Client2_Connected (Successful As Boolean)
    If Successful Then
        If Stream2.IsInitialized =True Then
            Stream2.Close
        End If

        Stream2.Initialize(Me,"Stream2")
        Stream2.Start(Client2.InputStream,Client2.OutputStream)
        Send(Mode)  'instruction to the server via other stream to read webcam
    Else
        ToastMessageShow(LastException.Message, True)
    End If  
End Sub

Sub Stream2_NewObject(Key As String, Value As Object)
    If Key="Webcam" Then
        Dim filename As String = Value
        If File.Exists("/storage/extSdCard/Domotica","camview.jpg") Then
            File.Delete("/storage/extSdCard/Domotica","camview.jpg")
        End If
        File.Copy(Stream2.TempFolder,filename,  "/storage/extSdCard/Domotica", "camview.jpg")
    End If          
End Sub

The NewObject sub is never activated; the program aborts before.

The program uses another stream as AsyncStreamsText, to exchange text data with the sever; that works great.

During latest test after the error message mentionned before; following log appeared:
"sending message to waiting queue (astream_newstream)"
"running waiting messages (1)"

After a while the program continued and the correct file length was shown; my log.

Then the message:
"java.lang.NegativeArraySizeException: -2555937"

I hope you can find something.

Harry
 
Last edited:
Upvote 0

HARRY

Active Member
Licensed User
Longtime User
May be it is a matter of the versions of the AsyncStreamsObject.bas.

What is the size of the most recent version of the AsyncStreamsObject.bas for B4a and B4j? A version is not always mentionned in the code

I have different sizes for each of them.

Harry
 
Upvote 0

HARRY

Active Member
Licensed User
Longtime User
Made some progress.

For B4A I use AsyncStreamsObject.bas version 4.3; for B4J I use AsyncStreamsObject.bas version 2.8.

A valid jpg file is created in /storage/emulated/0/Android/data/Home.App/files/. These files just have a simple number, but when the extension .jpg is added, it is correctly displayed.

What still is missing is the Stream2_NewObject(Key As String, Value As Object) event. Are the versions correct?

Harry
 
Upvote 0

HARRY

Active Member
Licensed User
Longtime User
Hi Erel,

I did what you suggested. Exactly the same result: the file is transferred from the raspberry tot my samsung phone and stored in /storage/emulated/0/Android/data/b4a.example/files with a number as name. The contents are correct. But also here astreamO_NewObject(Key As String, Value As Object) is not raised for Send File. Send Form, Sent Drawing work as it should.

Harry
 
Upvote 0
Top