A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

本帖最后由 大西洋 于 2015-4-26 22:41 编辑

程序运行后会在下面这段代码的第四行报错:
错误提示:Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0    数组越界了
  1. public int compare(InetAddress i1,InetAddress i2){
  2.         String[] str1 = i1.toString().split(".");
  3.         String[] str2 = i2.toString().split(".");
  4.         int num = new Integer(str1[1]).compareTo(new Integer(str2[0]));
  5.             if(num==0){
  6.                 num = new Integer(str1[1]).compareTo(new Integer(str2[1]));
  7.                 if(num==0){
  8.                     num = new Integer(str1[2]).compareTo(new Integer(str2[2]));
  9.                     if(num==0){
  10.                         num = new Integer(str1[3]).compareTo(new Integer(str2[3]));
  11.                     }
  12.                 }
  13.             }
  14.         
复制代码


请问这是什么原因??谢谢

2 个回复

倒序浏览
能把完整的代码给出吗?
回复 使用道具 举报
传入的数据都不知道。。。
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马