简体   繁体   中英

Why aren't arguments working in eclipse?

I am trying to learn how to code with Java and I am now just learning arguments using Eclipse. I am reading the book Sam's Teach Yourself Java in 24 Hours and I am following the book completely; however, it is not working in eclipse. My code is the following:

public class BlankFiller {
    public static void main(String[] args) {
        System.out.println("The " + arguments[0]
                + " " + arguments[1] + " fox "
                + "jumped over the "
                + arguments[2] + " dog.");
    }
}

Then I put my arguments in by going to RunRun ConfigurationsArguments and I type in "retromingent purple lactose-intolerant" into the Program Arguments tab, hit apply then run but it just gives me this error:

Exception in thread "main" java.lang.Error: Unresolved compilation problem
        arguments cannot be resolved to a variable
        arguments cannot be resolved to a variable
        arguments cannot be resolved to a variable

        at BlankFiller.main(BlankFiller.java:4)

What am I doing wrong?

You named the formal parameter args but you are trying use the variable arguments in the body of the method. Change one or the other so they match.

By the way—welcome to SO. In the future, please don't post your code on a separate web site like that. Unless it is absolutely necessary to do otherwise, include everything that is relevant directly in the question itself.

Try this:

public static void main(String[] arguments)

You had named the String[] parameter as args , but were referencing it as arguments . The name you use doesn't really matter - as long as is the same in both parts.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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