ArrayIndexOutOfBoundsException error
Code:
public class Test{
public static void main (String[] args){
//checkwhether first command-line argument is "Something"
if(args[0] == "Something")
{
//do something
}
}
}
I get the error ArrayIndexOutOfBoundsException:0, something I find strange. String[] args accepts string arrays, so I am just checking whether the first string equals "Something" in the command line but every time I run, I get this error, and I can't figure out what is the problem?
Re: ArrayIndexOutOfBoundsException error
If there is no first command line argument there is no args[0] String. b.t.w. don't compare Strings for equality with the == operator, use the String.equals( ... ) method instead.
kind regards,
Jos
Re: ArrayIndexOutOfBoundsException error
Thanks, yeah you are right. Such a silly mistake. Also using == wasn't right apparently, only after I used equals did it work.