错误:爪哇链表问题
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 3, Size: 2
at java.util.LinkedList.checkElementIndex(LinkedList.java:553)
at java.util.LinkedList.get(LinkedList.java:474)
at InterfacePackage.Main.main(Main.java:116)
Java Result: 1
代码(缩短):
if(input.length() > 0)
{
if(command.size() == 1)
{
switch(command.get(0).toLowerCase())
{
case "exit":
case "qqq":
active = false;
break;
default:
System.out.println("invalid input, for complete list of commands enter 'help'...");
break;
}
}
else if(command.size() > 1)
{
if(command.get(0).equalsIgnoreCase("shutdown") && command.size()==3)
{
Shutdown shutdown = new Shutdown();
shutdown.Start(command);
}
else if(((command.get(0).equalsIgnoreCase("scan")
&& command.get(1).equalsIgnoreCase("ips"))
|| command.get(3).equalsIgnoreCase("/e"))
&& (command.size()>=2 || command.size()<4))
{
SystemsIPs sips = new SystemsIPs();
sips.Start(command);
}
else
{
System.out.println("invalid input, for complete list of commands enter 'help'...");
}
}
}
当用户进入不在else if(command.size() > 1)
环存在的线内的两个串会出现错误。
例如,如果用户输入:hello world
程序会产生此错误。
所以这是一个基于用户输入到控制台来执行各种事情的程序。我一直在收到这个错误,并想知道是什么原因造成的。我知道我可以抓住它,但我真的想知道是什么导致了这个错误。
如果你猜(或实际想出一个明智的答案),为什么你认为它发生了什么? –
你正在请求索引3到一个大小为2的列表。 –
Lol没关系,我看到我做错了什么(: – Arc