save receving data into an array list
in
Programming Questions
•
1 year ago
Here I receive udp data , I want to save the packets received into an array list . but I don't know how to use it . while I tried to add items to my arraylist outside setup method it gaves me error .
- void receive(byte[] data, String HOST_IP, int PORT_RX) {
- receivedFromUDP ="";
- for (int i = 0; i < data.length; i++) {
- receivedFromUDP += str(data[i]) + " ";
- //println(receivedFromUDP);
- int j = 0 ;
- while ( j<data.length ) {
- if ( data[2*j] < 0 && data[2*j+1] < 0 ) {
- data[2*j] = (byte)(-data[2*j]);
- data[2*j+1] = (byte)(-data[2*j+1]);
- float[] bin1 = new float[] {
- ((-1) * unbinary(binary(data[2*j+1]-1)+binary(data[2*j])))
- };
- }
- else {
- float[] bin2 = new float[] {
- (unbinary(binary(data[2*j+3])+binary(data[2*j+2])+binary(data[2*j+1])+binary(data[2*j])))
- };
- floats.add((unbinary(binary(data[2*j+3])+binary(data[2*j+2])+binary(data[2*j+1])+binary(data[2*j]))));
- println(" array item " + j + "is" + bin2[i]);
- }
- j = j + 2;
- }
- }
- [javac] C:DOCUME~1T0P4568LOCALS~1Tempandroid593495203186330623.pdesrcchangethispackageeforesubmitting othemarketuudp3.java:65: cannot find symbol
- [javac] symbol : method add(int)
- [javac] location: class java.util.ArrayList<java.lang.Float>
- [javac] floats.add((unbinary(binary(data[2*j+3])+binary(data[2*j+2])+binary(data[2*j+1])+binary(data[2*j]))));
- [javac] ^
- [javac] 1 error
1