我写了以下java代码。抛出数组索引超出范围异常
Exceptions: exception_name = java.lang.ArrayIndexOutOfBoundsException
exception_message = Array index out of range: 1
有些人可以解决这个问题PLZ
public class UnifiedClus1toNfastfastsamehost extends UnifiedClus1toNfastfastsamehostHelper
{
/**
* Script Name : <b>UnifiedClus1toNfastfastsamehost</b>
* Generated : <b>Aug 3, 2007 1:16:35 AM</b>
* Description : Functional Test Script
* Original Host : WinNT Version 5.1 Build 2600 (S)
*
* @since 2007/08/03
* @author Administrator
*/
String[] dataToPass = new String[1];
public void testMain(Object[] args)
{
String options = "" + args[0];
callScript("Cleanup");
functions.formatall();
dataToPass[0]= "resyncdatagen";
callScript("Clus1toNfastfastsamehost",dataToPass);
dataToPass[0]= "configurepair1";
callScript("Clus1toNfastfastsamehost",dataToPass);
if (options.toLowerCase().contains("Failover"))
{
dataToPass[0]= "failover";
callScript("Clus1toNfastfastsamehost",dataToPass);
}
dataToPass[0]= "WFE1";
callScript("Clus1toNfastfastsamehost",dataToPass);
dataToPass[0]= "configurepair2";
callScript("Clus1toNfastfastsamehost",dataToPass);
dataToPass[0]= "WFE2";
callScript("Clus1toNfastfastsamehost",dataToPass);
sleep(180);
dataToPass[0]= "vsnap1";
callScript("Clus1toNfastfastsamehost",dataToPass);
dataToPass[0]= "dataverf1";
callScript("Clus1toNfastfastsamehost",dataToPass);
/* if (options.toLowerCase().contains("failover"))
{
dataToPass[0]= "diffdatagen1fover";
callScript("Clus1toNfastfastsamehost",dataToPass);
}
else
if (options.toLowerCase().contains("normal"))
{
dataToPass[0]= "diffdatagen1normal";
callScript("Clus1toNfastfastsamehost",dataToPass);
}
dataToPass[0]= "vsnap2";
callScript("Clus1toNfastfastsamehost",dataToPass);
dataToPass[0]= "dataverf2";
callScript("Clus1toNfastfastsamehost",dataToPass);
dataToPass[0]= "clean";
callScript("Clus1toNfastfastsamehost",dataToPass);
dataToPass[0]= "formatallsource";
callScript("Clus1toNfastfastsamehost",dataToPass);
if (options.toLowerCase().contains("failover"))
{
dataToPass[0]= "formatallclusfover";
callScript("Clus1toNfastfastsamehost",dataToPass);
}
else
if (options.toLowerCase().contains("normal"))
{
dataToPass[0]= "formatallclusnormal";
callScript("Clus1toNfastfastsamehost",dataToPass);
}*/
}
}
答案 0 :(得分:1)
不幸的是,您的异常没有显示源文件或行号,这让我们猜不到。
我没有在所显示的代码中看到任何下标1的使用,因此问题很可能出现在其中一个被调用的方法中。
if (options.toLowerCase().contains("Failover"))
包含一个错误:一旦你小写options
,结果字符串将不包含"Failover"
中的大写“F”!
答案 1 :(得分:0)
在调用testMain(Object [] args)时检查param“args”不应为null。最好在方法本身中进行空检查
String options =“”; if(args!= null){ options = options + args [0]; }