Results 1 to 3 of 3
- 05-12-2010, 08:04 AM #1
Member
- Join Date
- May 2010
- Posts
- 1
- Rep Power
- 0
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?
- 05-12-2010, 08:12 AM #2
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
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?
- 05-13-2010, 03:48 PM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,385
- Blog Entries
- 7
- Rep Power
- 17
Similar Threads
-
Runtime error "Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
By shantimudigonda in forum New To JavaReplies: 1Last Post: 11-20-2009, 07:58 PM -
Exception in thread "main" java.lang.NullPointerException at LinkedList.main(Link
By kavitha_0821 in forum New To JavaReplies: 6Last Post: 07-16-2009, 03:30 PM -
Exception in thread "main" java.lang.NullPointerException at LinkedList.main(Link
By kavitha_0821 in forum New To JavaReplies: 1Last Post: 07-16-2009, 10:35 AM -
ERROR: Exception in thread "main" java.lang.NoSuchMethodError: main
By barney in forum New To JavaReplies: 1Last Post: 08-07-2007, 07:10 AM -
ArrayList: Exception in thread "main" java.lang.NullPointerException
By susan in forum New To JavaReplies: 1Last Post: 07-16-2007, 06:32 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks