The error happen at the very first iteration of your loop. You access args
which is an array that gets filled with the so called command-line arguments
. If you don't pass any, that array is empty, and that is why you get that error.
Take a look at the official documentation to learn of to pass command line argument to your java applications here. It cannot hurt =)
If you are using eclipse take a look here