Reputation: 21
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 Run → Run Configurations → Arguments 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?
Upvotes: 0
Views: 271
Reputation: 234795
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.
Upvotes: 8
Reputation: 235984
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.
Upvotes: 1