The code below works as long as the argument in the run configuration equals “-output”. But when the arguments are empty the compiler throws and ArrayOutOfBoundsException.
The point of this piece of code would eventually be to;
– Perform an action when -output is written in the run configurations arguments
– Perform something else if the arguments are empty or different from -output
I found many problems that looked like this one. But I’ve been working on a solutions for far to long, so I started a new post. Help is very much appreciated.
...
public static void main(String[] args) {
Version_5 v5 = new Version_5("Test");
{
if(args[0].equals("-output")){
System.out.println("It works");
}
}
}
...
You need to check if you have arguments first, that’s all.
You might also consider using an argument-parsing library, of which there are several.
What are the extra brackets for?