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 Basics TreeStory.java code mistakes

Good afternoon. My workspace has a bunch of errors program simply won't run. Can anyone point at my mistakes?

https://w.trhou.se/o4wvyjc2q4

treehouse:~/workspace$ javac TreeStory.java
Picked up JAVA_TOOL_OPTIONS: -Xmx128m
Picked up _JAVA_OPTIONS: -Xmx128m
TreeStory.java:3: error: class, interface, or enum expected
public static void main(String[] args) {
^
TreeStory.java:11: error: class, interface, or enum expected
String ageAsString = console.readLine("How old are you? ");
^
TreeStory.java:12: error: class, interface, or enum expected
int age = Integer.preseInt(ageAsString);
^
TreeStory.java:13: error: class, interface, or enum expected
if (age <13){
^
TreeStory.java:17: error: class, interface, or enum expected
System.exit(0);
^
TreeStory.java:19: error: class, interface, or enum expected
String name = console.readLine("Enter your name: ");
^
TreeStory.java:20: error: class, interface, or enum expected
String adjective = console.readLine("Enter an ajective: ");
^
TreeStory.java:21: error: class, interface, or enum expected
String noun = console.readLine("Enter an noun: ");
^
TreeStory.java:22: error: class, interface, or enum expected
String adverb = console.readLine("Enter an adverb: ");
^
TreeStory.java:23: error: class, interface, or enum expected
String verb = console.readLine("Enter an verb ending in -ing: ");
^
TreeStory.java:24: error: class, interface, or enum expected
console.printf("Your TreeStory:\n-------------\n");
^
TreeStory.java:25: error: class, interface, or enum expected
console.printf("%s is a %s %s. ",name,adjective,noun);
^
TreeStory.java:26: error: class, interface, or enum expected
console.printf("They are always %s %s.\n",adverb,verb);
^
TreeStory.java:31: error: class, interface, or enum expected
}
^
14 errors
treehouse:~/workspace$

2 Answers

Hi Roman. Besides the 2 errors spotted by Tonnie, the main problem here is that you forgot to create a class. That is what this error message means:

TreeStory.java:3: error: class, interface, or enum expected public static void main(String[] args) {

You should include the following line at the top, under import:

public class TreeStory {

Not forgetting to close the curly bracket at the very bottom of course.

Hope that helps :)

Thank you, Lauren Moineau Great answer

You're welcome Roman Sliusarchuk . Glad I could help :)

Tonnie Fanadez
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Tonnie Fanadez
UX Design Techdegree Graduate 22,796 Points

Lauren Moineau you're a Java syntax star. After writing out so made java classes I surely don't know how I could have missed out the fact that Roman Sliusarchuk didn't declare the class. It is the first thing to see, isn't it?

It's only the beginning of my journey and it's a really good place to start. I end of February I am staring a coding Bootcamp "CyberTek" in Tysons Corner, VA to become a JAVA SDET(Automation Testing). I believe it's a great place to start before my classes that way I will have at least some base knowledge so I won't feel lost. So far great material and support.

Haha! Thanks Tonnie Fanadez! I think we're so used to looking for the small bugs (typo, missing parenthesis or semi -colon...) that we sometimes overlook the elephant in the room :) That's why an extra pair of eyes always helps. It was great team work here :)

It sounds like a great plan Roman Sliusarchuk! I agree, the course content and support here are great. Good luck with the classes! :)

Tonnie Fanadez
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Tonnie Fanadez
UX Design Techdegree Graduate 22,796 Points

Hi Roman Sliusarchuk ,

How are you liking Java? I noted only 2 problems on your code that you shared.

The first error is a spelling mistake and it is on line 12 and this is how you should write it:

int age = Integer.parseInt(ageAsString);

The next problem I think is on line 17. The if statement closing bracket [ } ]should be after line 17 i.e.

System.exit(0); }

Insert the closing bracket there and don't forget to remove the last closing bracket on your code i.e. closing bracket on line 34 should be deleted.

Try to run the code again after these 2 changes and let us know.

Cheers Buddy

Thank you, it is challenging but I like it so far, unfortunately, those changes did not do anything still same issue I'll try to retake the course and make sure I write code correctly without rush.

Tonnie Fanadez
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Tonnie Fanadez
UX Design Techdegree Graduate 22,796 Points

Roman Sliusarchuk too bad it did not work out, unfortunately I don't see any other problem.

Just try writing the code again and remember to save your work so that the new changes take effect.

Good luck.