Results 1 to 3 of 3
  1. #1
    sniperpig is offline Member
    Join Date
    May 2010
    Posts
    1
    Rep Power
    0

    Default Exception in thread "main" java.lang.ArrayIndexOutOfBoundsExceptio

    Hi peeps
    I am having trouble with my codes.

    My codes are as follows
    import java.net.*;
    import java.util.*;


    class EchoClient {
    public static void main( String args[] ) throws Exception {
    DatagramSocket socket = new DatagramSocket();
    socket.setSoTimeout( 5000 );
    byte[] buffer = args[1].getBytes();
    DatagramPacket packet = new DatagramPacket(buffer,buffer.length,InetAddress.ge tByName(args[0]),7);
    socket.send( packet );
    Date timeSent = new Date();
    socket.receive( packet );
    Date timeReceived = new Date();
    System.out.println( ""+(timeReceived.getTime()-timeSent.getTime())+" ms "+new String(packet.getData(),0,packet.getLength()) );
    }
    }


    and the error is
    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
    at EchoClient.main(EchoClient.java:9)

    Anyone can assist?

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Did you put at least 2 values into args before doing byte[] buffer = args[1].getBytes();
    because you are trying to get the second item of the array?

    P.S Who is peeps?

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,538
    Blog Entries
    7
    Rep Power
    20

    Default

    Sigh, another spamming shoes salesman; reported.

    kind regards,

    Jos

Similar Threads

  1. Replies: 1
    Last Post: 11-20-2009, 07:58 PM
  2. Replies: 6
    Last Post: 07-16-2009, 03:30 PM
  3. Replies: 1
    Last Post: 07-16-2009, 10:35 AM
  4. Replies: 1
    Last Post: 08-07-2007, 07:10 AM
  5. Replies: 1
    Last Post: 07-16-2007, 06:32 AM

Posting Permissions

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