Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Java Objects (Retired) Delivering the MVP Arrays and Command Line Arguments

Error cannot find symbol

When i try and run the below code the compiler doesn't seem to be able to evaluate the length of the args variable and I get the below error. Why is this? This code is exactly the same as in the video...

public class Hangman {

public static void main(String[] args) {
    // Your amazing code goes here...
        if (args.length() == 0) {
            System.out.println("Please enter a word");
            System.exit(0);
        }
  Game game = new Game(args[0]);
        Prompter prompter = new Prompter(game);
        prompter.play();
}

}

And the error is:

Hangman.java:5: error: cannot find symbol
if (args.length() == 0) {
^
symbol: method length()
location: variable args of type String[]
1 error

I see you're sorted, which is great.

Yes, the length for this exercise is a property not a method so the parentheses aren't needed. Be careful, though, as there are times when the length must be obtained with a method as there is no such property. Then, you'll need the brackets. Some arrays, for example, use a method to access their length.

Steve.

1 Answer

You don't need the "()" after length. :wink:

Thanks Isaiah. Actually just figured it out myself!

you are welcome and good job! :+1: