Android Question Problem with the array

stopa

New Member
Licensed User
Longtime User
Hello,
I'm working with my GPS project. At the moment, it's only test without gps, I'm sending random values from microcontroller to my device via bluetooth. Receiving works good, but I would like to save all the values of received signal in the array, but I can't do this. Array is empty all the time and I receive communicate from logs: "ArrayIsOutOfBoundException". I can't fix this.

It's my code (condensed a bit):
B4X:
Dim WspX() As Double
-----------
If Buffer.Length=5 Then
  If Odebrane.StartsWith(Chr(104)) Then
  If Odebrane.EndsWith(Chr(13)) Then
  Try
      k=k+1
      Suwak2=Odebrane.SubString2(1,4)
    Val3 = NumberFormat(Suwak2,3,0)
    Val4 = Val3/250 'it's double
   

    For i=0 To k
        WspX(i)=Val4
    Next
        Log(WspX(i))

    Xmin = Activity.Width/2
  Catch
  Log(LastException.Message)
  End Try
  End If
  End If

Maybe it's better way to do this, without an array, but I don't have idea.

Waiting for some tips.

Regards.
 

TomA

Active Member
Licensed User
Longtime User
You don't seem to have given the array any dimension so it is zero length. You need to identify the size - Dim WspX(some value) - before you start to use it. If you do not know how big the array would need to be, I would suggest you replace it with a List since you can just keep adding to it as needed. A list is very easy to use - see http://www.b4x.com/android/help/collections.html#list
 
Upvote 0

stopa

New Member
Licensed User
Longtime User
Hello,
I was trying before with List, but something was wrong. I woke up today and fixed the code, thank you for help :)
 
Upvote 0
Top