0

I have written following java code. It is throwing array index out of range exception

Exceptions: exception_name = java.lang.ArrayIndexOutOfBoundsException 
    exception_message = Array index out of range: 1

Can some resolve this issue 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);
        }*/
    }
}
3
  • Please post the whole exception with stack trace. Commented Jan 6, 2010 at 6:40
  • 1
    Duplicate of stackoverflow.com/questions/2011247/string-convertion-in-java? or this may be additional information that was intended for that other question. Perhaps this needs some moderation assistance? Commented Jan 6, 2010 at 6:42
  • String options = "" + args[0]; Why do you use this ? You could just cast it to String, if(args[0] instanceof String) String options = (String) args[0]; . And Kevin+1. Commented Jan 6, 2010 at 6:53

2 Answers 2

1

It's unfortunate your exception doesn't show source file or line number, this leaves us to guess.

I don't see any use of a subscript 1 in the code shown, so the problem is likely in one of the called methods.

if (options.toLowerCase().contains("Failover"))

contains a bug, though: Once you lowercase options, the resulting String will not contain a capital "F" as in "Failover"!

Sign up to request clarification or add additional context in comments.

Comments

0

Check that while making call to testMain(Object[] args) the param "args" should not be null. Better put a null check in the method itself

String options = ""; if (args!=null){ options = options+ args[0]; }

3 Comments

-1 for being completely offtopic as the exception is not thrown from the shown code, and another -1 for blindly suggesting StringBuilder because two String instances were concatenated once.
Interestingly enough, "" + null yields the string "null". Perhaps not as intended, but it won't explode. @Bombe: Agree completely on 2nd criticism, it is downright WRONG to replace simple concatenation with SB. Zillions of Java programmers don't understand when SB is appropriate.
Yep, got it, but some details were missing from the question itself.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.