configurationnetbeanscommand-line-argumentsnetbeans-6.9

Netbeans configuration - arguments not recognised in ide


I'm working my way through the Java in 24 hours book (which is actually quite good) and have hit a problem in that the simple test programs aren't recognising the arguments I put in the configuration window, i'm following the instructions exactly as written and have tried with different code snippets to no avail.

This is the latest script, note the 'No arguments println...

class newSqrt {
    public static void main(String[] args) {
        int number = 144;
        if (args.length > 0) {
            number = Integer.parseInt(args[0]);
        } else {
            System.out.println("No arguments!");
        }
        System.out.println("The square root of "
            + number + " is " + Math.sqrt(number));
    }
}

I pasted a screenshot of the configuration clearly showing the argument 100 so I should see the square root of 100 but I get the output below clearly proving that it is just ignoring the argument from the configuration. I'm sure i'm not the only one who has had this happen, I have tried various google searches but nothing has helped track down the problem.

run:
No arguments!
The square root of 144 is 12.0
BUILD SUCCESSFUL (total time: 0 seconds)


Solution

  • Right-Click on the top-most node of your project in the Projects tab, and click on Properties.

    alt text

    In the Project Properties, click on Run, and then in Arguments: enter an appropriate value. Then click on OK

    alt text

    Run the project by clicking on the Run toolbar button (or through the Run menu). If prompted for the main class, select newSqrt. You should see the appropriate output.

    alt text