我写了下面的java代码。抛出数组索引超出范围异常
Exceptions: exception_name = java.lang.ArrayIndexOutOfBoundsException
exception_message = Array index out of range: 1这个问题能不能解决?
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);
}*/
}
}发布于 2010-01-06 15:51:39
不幸的是,您的异常没有显示源文件或行号,这让我们猜测。
我在显示的代码中看不到下标1的任何用法,所以问题可能出在某个被调用的方法中。
if (options.toLowerCase().contains("Failover"))包含一个错误,但是:一旦你小写options,结果字符串将不会像在"Failover"中那样包含大写的"F“!
发布于 2010-01-06 14:43:34
检查在调用testMain(Object[] args)时,参数"args“不应该为空。最好在方法本身中放入一个空检查
字符串选项= "";if (args!=null){ options = options+ args;}
https://stackoverflow.com/questions/2011321
复制相似问题