B4J Question Problem with AsyncStreamsObject

HARRY

Active Member
Licensed User
Longtime User
I get a null pointer exception in the code of AsyncStreamsObject on the following place:

Code:
Public Sub WriteFile (Key As String, Dir As String, FileName As String)
    Dim len As Long = File.Size(Dir, FileName)
    If len = 0 Then
        Log("Error getting file size.")
        Return
    End If
    Dim name(1) As String
    Dim raf As RandomAccessFile = sharedWrite(Key, name)
    raf.WriteByte(TYPE_FILE, raf.CurrentPosition)
    sharedWriteComplete(raf, name(0))
    astream.WriteStream(File.OpenInput(Dir, FileName), len)
End Sub

The function is called as follows:
Code:
Sub SendFile
    If File.Exists("/home/pi/MyApps/Domo/Images","Webcam" & ImageNr & ".jpg") = True Then
        Stream3.WriteFile("Webcam","/home/pi/MyApps/Domo/Images","Webcam" & ImageNr & ".jpg")
    Else
        Stream2.Write("-4"& CRLF)
    End If     
End Sub

The file exists.

The error occurs on the line: Dim raf .... The key="Webcam"; the name = empty.

I use AsyncStreamsObject version 1.1 and jRandomAccessFile version 2.30.

Harry
 
Last edited:
Why are you using AsyncStreamsObject? Unless the files are very large then it is better (mainly simpler) to use B4XSerializator.

With B4XSerializator you can send a Map or a custom type with all the data needed:
Code:
Dim bmp() As Byte = Bit.InputStreamToBytes(File.OpenInput(...))
Dim dataToSend() As Byte = ser.ConvertObejctToBytes(CreateMap("FileName": "MyFile", "Data": bmp))
astream.Write(dataToSend)
 
Upvote 0
Back
Top