Java netbeans commadline argument passed

I pass the command line argument using Netbeans, but I get 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]);
      }
} 

Conclusion:

Count : 0

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
+3
source share
4 answers

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

+5
source

Since your result Count : 0, then the array argshas lengthof 0, which means that no arguments are passed.

arg[0], , , . . , 0 length - 1.

args , , , Netbeans , , Netbeans .

+2

, /run/arguments, ( → run), , , . , , "". , .

0

Click "Final proj" and run, and not the main project for netbeans 6.9. U will get an answer.

-1
source

Source: https://habr.com/ru/post/1759470/


All Articles