当前位置: 技术问答>java相关
重分求解,为什么我碰见的错误都这么奇怪呀?
来源: 互联网 发布时间:2015-08-01
本文导语: 我昨天写了一个程序,昨天可以好好的运行jdk1.2.2 今天我换成jdk1.2.1缺又运行不了了,出现如下错误: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException at Receiver.main(Compiled code) 源程序如下: import java.net.*; clas...
我昨天写了一个程序,昨天可以好好的运行jdk1.2.2 今天我换成jdk1.2.1缺又运行不了了,出现如下错误:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException
at Receiver.main(Compiled code)
源程序如下:
import java.net.*;
class Receiver
{
public static void main(String args[])throws Exception
{
int rPort=Integer.parseInt(args[0]);
DatagramSocket sock = new DatagramSocket(rPort);
byte[] takeLine = new byte[80];
DatagramPacket p;
String killCommand = args[1];
String receiveString = "";
while(!receiveString.equals(killCommand))
{
p = new DatagramPacket(takeLine,takeLine.length);
sock.receive(p);
System.out.println(receiveString = new String(p.getData(),0,0,p.getLength()));
}
}
}
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException
at Receiver.main(Compiled code)
源程序如下:
import java.net.*;
class Receiver
{
public static void main(String args[])throws Exception
{
int rPort=Integer.parseInt(args[0]);
DatagramSocket sock = new DatagramSocket(rPort);
byte[] takeLine = new byte[80];
DatagramPacket p;
String killCommand = args[1];
String receiveString = "";
while(!receiveString.equals(killCommand))
{
p = new DatagramPacket(takeLine,takeLine.length);
sock.receive(p);
System.out.println(receiveString = new String(p.getData(),0,0,p.getLength()));
}
}
}
|
你肯定输入的参数个数不对吧
|
查查看是在使用哪个数组的时候越界了