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 The Challenge

Nikola Vichev
Nikola Vichev
1,668 Points

Hi, guys, I keep getting this error and I just can't figure it out, help, please

import java.io.Console;

public class Main {

public static void main(String[] args) { Console console = System.console();

Cow cow = new Cow("Larry");

System.out.printf("The cow's name is %s,
                  cow.getCowName());

} }

Main.java:11: error: illegal start of expression
cow.getCowName());
^
Main.java:11: error: ';' expected
cow.getCowName());

Steven Parker
Steven Parker
229,670 Points

To allow your issue to be replicated, make a snapshot of your workspace and post the link to it here.

2 Answers

Steven Parker
Steven Parker
229,670 Points

There's a few issues:

  • in Main.java line 10, the string is missing the ending quote mark
  • Main.java line 11 calls "getCowName" but the method in Cow.java is just "getName"
  • in Cow.java line 11 the constructor is private instead of public
Nikola Vichev
Nikola Vichev
1,668 Points

Thanks a lot, Steven. I still don't quite get everything, but I'll keep pushing. At least I got it working with your help