How to pass argument to main class in netbeans?

UPDATED: 17 April 2012
netbeans
Lot of people asking me "How to pass argument to main class in netbeans?". Its very easy but you didn't explored well enough. Let me show you how you can do it.





Step 1: Right click on project and click on "Set as Main Project". Now Right click on project and go to "Properties" > "Run" option as shown in below image.

netbeans properties

Step 2 : You can see that there is browse... option for "Main Class" click on it. And select the class you wanna pass the argument. The class you select as a Main Class will always run as first class on starting of the project.


netbeans properties

Step 3: Pass the argument as show in below image. If you wanna pass multiple argument separate it by space. 

Note : If you run the class by right clicking on file. It won't accept argument and give you ArrayoutofBound Exception. To use that argument you must run whole project. Use PLAY button on top tool bar or right click on project and click RUN.
  •     - int  : 10
  •     - String single word : Hello
  •     - String more then one word : 'Hello World' (use single quote)
netbeans properties

0 comments :