【发布时间】:2016-07-09 11:41:05
【问题描述】:
我试图用“.”分割一个 IP 地址。但是代码正在生成异常。
Exception Message : "Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at decimaltobinary.DecimalToBinary.main".
帮我解决。这是我的代码。
String[] ipAddresses=IP.split(".");
String ip1=ipAddresses[0];
String ip2=ipAddresses[1];
String ip3=ipAddresses[2];
String ip4=ipAddresses[3];
【问题讨论】:
-
你没有包含所有的代码。
IP定义在哪里? -
这意味着你的数组中没有元素。打印分割前IP的原始值。
-
我觉得你需要逃跑
. -
我认为你应该使用
'.'而不是".",因为你应该用字符而不是字符串来分割 -
为什么会有 [scala] 标签?