首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >java字符串转换

java字符串转换
EN

Stack Overflow用户
提问于 2010-01-06 14:36:58
回答 2查看 233关注 0票数 0

我写了下面的java代码。抛出数组索引超出范围异常

代码语言:javascript
复制
Exceptions: exception_name = java.lang.ArrayIndexOutOfBoundsException 
    exception_message = Array index out of range: 1

这个问题能不能解决?

代码语言:javascript
复制
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);
        }*/
    }
}
EN

回答 2

Stack Overflow用户

发布于 2010-01-06 15:51:39

不幸的是,您的异常没有显示源文件或行号,这让我们猜测。

我在显示的代码中看不到下标1的任何用法,所以问题可能出在某个被调用的方法中。

代码语言:javascript
复制
if (options.toLowerCase().contains("Failover"))

包含一个错误,但是:一旦你小写options,结果字符串将不会像在"Failover"中那样包含大写的"F“!

票数 1
EN

Stack Overflow用户

发布于 2010-01-06 14:43:34

检查在调用testMain(Object[] args)时,参数"args“不应该为空。最好在方法本身中放入一个空检查

字符串选项= "";if (args!=null){ options = options+ args;}

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2011321

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档