简体   繁体   English

在NetBeans中使用Java命令行参数时遇到问题

[英]Trouble Using Java Command-Line Arguments in NetBeans

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)! 我查看了有关在人类已知的NetBeans中使用命令行参数的每个教程,我开始认为这不是我(着名的遗言)!

项目属性

在此输入图像描述

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. 我正确地设置了我的主类,放入我的参数,但是我仍然总是按照说明我的参数长度小于4的行。实际上,当我尝试打印args [0]时,我得到一个IndexOutOfBoundsException 。 Any thoughts? 有什么想法吗?

Here is the top of my Java file, as requested! 这是我的Java文件的顶部,按要求! 更完整的文件图像

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: 我试图包括我采取的所有步骤:

第1步

第2步

第3步

Womp. Womp。 第四步

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. 你的主要类是WordCloudGenerator ,从我可以看出你所显示的图像中的代码不是来自WordCloudGenerator类。

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: 或者,如果您确实需要两个带有main方法的类,那么WordCloudGenerator需要将这些args转发到您的其他类,如下所示:

public class WordCloudGenerator
{

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

Now your main method in the other class should function correctly. 现在你在另一个类中的main方法应该正常运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM