java netbeans commadline argument passing

Samurai picture Samurai · Aug 13, 2010 · Viewed 6.9k times · Source

I am passing a command line argument using Netbeans but I get an ArrayIndexOutOfBoundsException.

My code is:

public class CmdLineArgumentPassing

{

      public static void main(String args[])
      {        
         System.out.println("Count : " + args.length);

         System.out.println("i : "+args[0]);
      }
} 

The output is:

Count : 0

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0

Answer

TofuBeer picture TofuBeer · Aug 13, 2010

Right mouse click on the project, select Properties, go to the Run page, add the command line arguments.