Results 1 to 4 of 4
Like Tree1Likes
  • 1 Post By Tolls

Thread: Exception in thread "SocketThread" java.lang.IllegalArgumentException: 0 > -257

  1. #1
    johnmerlino is offline Member
    Join Date
    May 2014
    Posts
    56
    Rep Power
    0

    Default Exception in thread "SocketThread" java.lang.IllegalArgumentException: 0 > -257

    I get the following error:

    Exception in thread "SocketThread" java.lang.IllegalArgumentException: 0 > -257
    at java.util.Arrays.copyOfRange(Arrays.java:3513)
    at com.guarddoggps.main.SocketThread.run(SocketThread .java:39)


    I have an array of unsigned chars in c sent over udp socket to java. It looks something like the following (although I changed the array contents a little here):

    Java Code:
    unsigned char msg[] = {0x28, 0xC2, 0x43, 0x80, 0x0, 0x0, 0xD};
    Now in Java I want to extract this portion of the array:

    0x28, 0xC2, 0x43, 0x80, 0x0, 0x0

    So I come up with this:
    Java Code:
                  byte[] buf = new byte[256];
                  DatagramPacket packet = new DatagramPacket(buf, buf.length);
                  socket.receive(packet);
                  
                  byte[] resp = packet.getData();              
                  int delimiter = Arrays.binarySearch(resp, (byte)0xD);
                                
                  byte[] data = Arrays.copyOfRange(resp, 0, delimiter);
    But it thinks the delimiter is out of range from resp byte array. I have no idea where this -257 comes from.
    Last edited by johnmerlino; 05-23-2014 at 01:22 AM.

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    4,036
    Rep Power
    6

    Default Re: Exception in thread "SocketThread" java.lang.IllegalArgumentException: 0 > -257

    The error is in line 39 of SocketThread. Where is that line?

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default Re: Exception in thread "SocketThread" java.lang.IllegalArgumentException: 0 > -257

    What is the value of delimiter after the binarySearch(???)?
    Have you read the API doc for the binarySearch() method to see what it returns?
    If you don't understand my response, don't ignore it, ask a question.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: Exception in thread "SocketThread" java.lang.IllegalArgumentException: 0 > -257

    Indeed, have you read the documentation for binarySearch to see what it expects as input.
    Norm likes this.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Replies: 5
    Last Post: 12-21-2011, 07:44 PM
  2. Replies: 4
    Last Post: 09-16-2011, 11:08 PM
  3. Replies: 6
    Last Post: 03-19-2011, 08:10 PM
  4. Replies: 12
    Last Post: 05-26-2009, 02:48 PM
  5. Replies: 1
    Last Post: 08-06-2007, 07:04 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •