Android Question Input Buffer

Discussion in 'Android Questions' started by freetoair, Sep 9, 2015.

  1. freetoair

    freetoair Member Licensed User

    I need to receive 2-byte coded unusual and this routine works pretty chaotic. Is the problem in the deletion of the buffer? When an error occurs get a message on the screen:


    An error has occurred in sub: main_astreams_nevdata (java line: 465)
    java.lang.ArrayIndexOutOfBoundsException: length = 1; Index = 1






    Code:
    Sub Astreams_NewData (Buffer() As Byte)
        
    Dim r As Int = 0
            r = ((
    Bit.ShiftRight(Buffer(0),4) * 100) + (Bit.ShiftRight(Buffer(1),4) * 10) + (Bit.And(Buffer(1),15))) * 2
                skbValue_ValueChanged(r, 
    False)                'Sub  that refreshes the LED bar
    End Sub
     
  2. RandomCoder

    RandomCoder Well-Known Member Licensed User

    You are not getting the data you expect. Buffer(1) is throwing the error because there is only one byte present i.e. length=1 in the error message. You could guard against this error by checking the size of the array of bytes before running your function.
     
    JordiCP likes this.
  3. freetoair

    freetoair Member Licensed User

    All right, I just added:

    If (Buffer.Length = 2) Then
    .....
    End If

    now works great. Thank you RandomCoder
     
    RandomCoder likes this.
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