Android Question AsyncStreamsObject -> java.nio.BufferUnderflowException

TheMightySwe

Active Member
Licensed User
Longtime User
What can be wrong when I get a java.nio.BufferUnderflowException in the AsyncStreamsObject Class?

B4X:
Private Sub astream_NewStream (Dir As String, FileName As String)
    Dim value As Object
    Dim deleteFile As Boolean = True
    If waitingForAnotherStream Then
        waitingForAnotherStream = False
        'this is the second part of the object
        Select waitingForType
            Case TYPE_BITMAP
                value = LoadBitmap(Dir, FileName)
            Case TYPE_FILE
                value = FileName 'just return the file name
                deleteFile = False
        End Select
    Else
        Dim raf As RandomAccessFile
        raf.Initialize(Dir, FileName, True)
       
        waitingForKey = raf.ReadObject(raf.CurrentPosition) ' <--- Crashes here
        waitingForName = raf.ReadObject(raf.CurrentPosition)
        waitingForType = raf.ReadSignedByte(raf.CurrentPosition)
       
        Select waitingForType
           
            Case TYPE_OBJECT
                value = raf.ReadObject(raf.CurrentPosition)
                raf.Close
            Case TYPE_FILE, TYPE_BITMAP
                'wait for the second part of the message
                waitingForAnotherStream = True
                raf.Close
                File.delete(Dir, FileName)
                Return '<--- return!!!
        End Select
       
    End If