B4J Question Compiling error with AsyncStreamsObject

Discussion in 'B4J Questions' started by HARRY, Apr 27, 2015.

  1. HARRY

    HARRY Active Member Licensed 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:

    Code:
    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
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    The module uses APIs only available in UI applications. If you are creating non-UI app then you will need to remove these calls.
     
  3. HARRY

    HARRY Active Member Licensed 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
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    You can use AsyncStreamsObject from a non-UI app. You just need to delete the two lines that use fx object.
     
  5. HARRY

    HARRY Active Member Licensed 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
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    Does the file arrive correctly to the device? If yes then it is not related to AsyncStreams.
     
  7. HARRY

    HARRY Active Member Licensed 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:

    Code:
    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",840020000)      
        
    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: May 3, 2015
  8. Erel

    Erel Administrator Staff Member Licensed User

    I'm sorry but it is very difficult to say what went wrong without seeing the full code.
     
  9. Erel

    Erel Administrator Staff Member Licensed User

    You should use File - Export as zip when uploading your projects.
     
  10. HARRY

    HARRY Active Member Licensed 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
     
  11. HARRY

    HARRY Active Member Licensed 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
     
  12. Erel

    Erel Administrator Staff Member Licensed User

  13. HARRY

    HARRY Active Member Licensed 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
     
  14. Erel

    Erel Administrator Staff Member Licensed User

    Put a breakpoint in astream_NewStream and see what happens after the file is transferred.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice