I get a ArrayIndexOutOfBoundsException. The cause is this snippet:

public static void main(String[] args) {
		//command line param
		try {
			[B]if (args[0] != null) {[/B]
				if (args[0].equals("printer")) { 
					printToFile = false;
				}
			}
		} catch (Exception oob) {
			oob.printStackTrace();
		}

I don't give the program any parameters when I start it up, so args[0] is null, but that shouldn't cause this error, should it?

No, args[0] is not null. The array args has length 0. So the args[0] gives you the exception since there is no '0' element; the length of the array is 0.
The elements of the args will never be null .
Depending on the number of parameters you pass the array args will be created with those parameters. So if you pass 2 parameters, the args will have length 2. args[0], args[1] will have those values.

Thanks. Very useful advice!

I'm now using the following:

if (args.length > 0) {
            if (args[0].equals("printer")) {
                printToFile = false;
            }
        } else {
            printToFile = true;
        }

and it works perfectly.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.