当前位置: 技术问答>java相关
请问为什么会出现这个错误java.lang.ArrayIndexOutOfBoundsException,怎么解决?
来源: 互联网 发布时间:2015-01-07
本文导语: 请问为什么会出现这个错误java.lang.ArrayIndexOutOfBoundsException,怎么解决?源代码如下: Phone = rs.getString("Phone"); Mobile = rs.getString("Mobile"); Fax = rs.getString("Fax"); Emai...
请问为什么会出现这个错误java.lang.ArrayIndexOutOfBoundsException,怎么解决?源代码如下:
Phone = rs.getString("Phone");
Mobile = rs.getString("Mobile");
Fax = rs.getString("Fax");
Email = rs.getString("Email");
Linkman = new String ((rs.getString("Linkman")).getBytes("iso8859-1"),"gb2312");
Abridge = rs.getString("Abridge");
Remarks = new String ((rs.getString("Remarks")).getBytes("iso8859-1"),"gb2312");
StringTokenizer e=new StringTokenizer(Phone,"-");
int count=e.countTokens();
int i=0;
if (count>0)
{
a=new String[count];
while(e.hasMoreTokens())
{
String token = e.nextToken();
a[i]=token;
i++;
}
}
//split
StringTokenizer second=new StringTokenizer(Fax,"-");
int number=second.countTokens();
int j=0;
if(number>0)
{
b=new String[number+1];
while(second.hasMoreTokens())
{
String to=(String)second.nextToken();
b[j]=to;
j++;
}
}
Phone = rs.getString("Phone");
Mobile = rs.getString("Mobile");
Fax = rs.getString("Fax");
Email = rs.getString("Email");
Linkman = new String ((rs.getString("Linkman")).getBytes("iso8859-1"),"gb2312");
Abridge = rs.getString("Abridge");
Remarks = new String ((rs.getString("Remarks")).getBytes("iso8859-1"),"gb2312");
StringTokenizer e=new StringTokenizer(Phone,"-");
int count=e.countTokens();
int i=0;
if (count>0)
{
a=new String[count];
while(e.hasMoreTokens())
{
String token = e.nextToken();
a[i]=token;
i++;
}
}
//split
StringTokenizer second=new StringTokenizer(Fax,"-");
int number=second.countTokens();
int j=0;
if(number>0)
{
b=new String[number+1];
while(second.hasMoreTokens())
{
String to=(String)second.nextToken();
b[j]=to;
j++;
}
}
|
try
{
你的代码;
}
catch(ArrayIndexOutOfBoundsException e)
{
System.out.println("数组越界");
}
{
你的代码;
}
catch(ArrayIndexOutOfBoundsException e)
{
System.out.println("数组越界");
}