PDA

Click to See Complete Forum and Search --> : Arguments in NetBeans 5.5


The VBer
Feb 25th, 2010, 03:33 PM
Okay, so after programming with VB for a year or two, i figured it's about time i learn another language. One of the beginner examples deals with arguments. Here's the code:
class BlankFiller {
public static void main(String[] args) {
System.out.println("The " + args[0]
+ " " + args[1] + " fox "
+ "jumped over the "
+ args[2] + " dog."
);
}
}

What the program should do is fill in the blanks (args).
In the example i'm using, it says to add arguments i must go to: Run -> Set Project Configuration -> Customize. Then, enter "BlankFiller" into the Main Class field. Then in the arguments field enter "retromingent purple lactose-intolerant" Then click okay. I found where to input this information in a different place than described.(probably different version on netbeans). Anyway, i enter the information and i get this error while running the program.
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at BlankFiller.main(BlankFiller.java:3)


The book I'm using mentions this error, but the solution is to enter the information in the arguments field as i said i did above. So, i have no idea why this is not working.

akhileshbc
Feb 26th, 2010, 12:39 AM
The arguments inside the main function are commandline arguments.... (That's what i think.. :D)... That is, if we pass something to our program, it will be stored in that array....

Check this link:

* http://www.dickbaldwin.com/java/Java032.htm

...:wave:

ComputerJy
Feb 26th, 2010, 05:15 AM
5.5! that's too old. Anyway, you can go to the default project's "Run" configuration in the project properties. Or click customize on the "default config" runtime After the "Main Class" which specifies the class to hold the main method e.g. BlankFiller in your case. You'll find a box for arguments. arguments are separated by whitespace either a space or a tab it doesn't matter

The VBer
Feb 26th, 2010, 04:51 PM
I got it to work, but it was by accident. The book says to run it by going to Run -> Run File. But that causing the error. So when i was trying to get it to work i simply clicked the Green arrow to run the program. The Green arrow is the same as going to Run -> Run Main Project.

And yes, i did upgrade to the latest version on NetBeans ;)

ComputerJy
Feb 26th, 2010, 04:57 PM
Yeah that too works :)
When running a file it just runs it doesn't compile other files or look at run-config