Trouble Using Java Command-Line Arguments in NetBeans

Viewed 296

I have looked at every tutorial on using command-line arguments in NetBeans known to man and I am starting to think it's not me (famous last words)!

Project Properties

enter image description here

This image is from right-clicking on the project and going to the run tab. I set my main class appropriately, put in my arguments, but I'm still always hitting the line that says that the length of my arguments is less than 4. In fact, when I try to print args[0] I get a IndexOutOfBoundsException. Any thoughts?

Here is the top of my Java file, as requested! More complete file image

Also, here is another more simple example with it still not working as I would expect. I've tried to include all the steps I took:

Step 1

Step 2

Step 3

Womp. Step 4

1 Answers

I am unable to reproduce your issue in my environment, however the most likely cause is that:

Your main class is WordCloudGenerator, and from what I can tell the code in the image you have shown is not from WordCloudGenerator class.

You need to make sure that your main class is set correctly in the properties window shown in the first image in your question. Or if you do want two classes with main methods, then WordCloudGenerator needs to forward those args onto your other class like so:

public class WordCloudGenerator
{

    public static void main(String[] args)
    {
        myOtherClass.main(args);
    }
}

Now your main method in the other class should function correctly.

Related