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 TreeStory Error

I keep getting an error : TreeStory.java:22: error: reached error at end of file while parsing console.printf("They are always %s %s.\n", adverb, verb);

![The alternate text]https://teamtreehouse.com/workspaces/7147612

14 Answers

Good evening,

The error message you are receiving, "reached error at the end of file while parsing," is generated if a curly bracket is missing at the end of the code. Make sure you have a closing bracket for both your class and your method. If there is no ending curly bracket, the compiler will throw this error. See the code below:

import java.io.Console;

public class TreeStory {

     public static void main(String[] args) {
          Console console = System.console();
          /*  Some terms:
               noun - Person, place or thing
               verb - An action
               adjective - A description used to modify or describe a noun
               Enter your amazing code here!
          */
         // __Name__ is a __adjective__ __noun__. They are always __adverb__ __verb__.
         String name = console.readLine("Enter a name: "); 
         String adjective = console.readLine("Enter an adjective: "); 
         String noun = console.readLine("Enter a noun: "); 
         String adverb = console.readLine("Enter an adverb: "); 
         String verb = console.readLine("Enter a verb ending with -ing: ");

         console.printf("Your TreeStory:/n------------\n"); 
         console.printf("%s is a %s %s. ", name, adjective, noun); 
         console.printf("They are always %s %s.\n", adverb, verb);
     } //Closing bracket for public static void main(String[] args) line
} //Closing bracket for public class TreeStory line.

The nice thing about the workspaces is when your cursor is next to a closing curly bracket, it will show you which opening bracket it relates to. Try it out!

I hope this message finds you well. Happy coding!

Hi Jeremiah,

Do you exactly where I'm supposed to place the curly bracket (s) in the Workspace? I tried to insert a curly bracket at the end of my code at the.....verb); but no luck. I guess I don't exactly know where to place them. I checked the Mr. Dennis' workspace and didn't see a closing bracket.

Thanks for the help!

Hi Hussain,

The curly brackets go at the end of your code for that particular method/class. Coding etiquette states they should be on separate lines by themselves, but as long as you have enough curly brackets to close out your code you will be fine. Each time you open a bracket, you must have a closing on at the end of it. I hope the below code helps in determining when/where/why you need the ending curly brackets.

public class Example { //class declaration, closing bracket will be at the very end of all code

       public static void main(String[] args) { //method declaration, closing bracket will be at the end of the code for the main method

// some code here

} //end of main method

      public static void anotherMethod() { //method declaration, closing bracket will be at the end of the code for the anotherMethod method.

//some code here

} //end of anotherMethod method

} //end of Example class

Thanks a lot Mr. Montano!

Hi Hussain,

I tried to access your workspace, but my browser said that the web page couldn't be found.

If you could post your code I may be able to help.

Have you closed the curly brackets, }, underneath the last line?

I don't remember if the instructor used curly brackets for this exercise?

Could you try it?

Is the instructor Mr. Craig?

Did you put it on the next line down? That may make a difference.

Hi Hussain,

Me again! I was just wondering if Jeremiah's answer has solved the problem, if it has you should click on the "Best Answer" button underneath his post and then I will know that you have solved the problem.

Thanks for your input Jeremiah! :)

Oh sorry Peter. Thanks for the help! You and Jeremiah have been great. Much appreciated!

Hi Peter,

I'll check it out now and get back to you very shortly.

Thanks!!

console.printf("Your TreeStory:/n------------\n"); console.printf("%s is a %s %s. ", name, adjective, noun); console.printf("They are always %s %s.\n", adverb, verb);

I keep getting an error on the last code when I try to run it.

I can't see any errors.

Would it be too hard to post all of your code in your project?

import java.io.Console;

public class TreeStory {

public static void main(String[] args) {
    Console console = System.console();
    /*  Some terms:
        noun - Person, place or thing
        verb - An action
        adjective - A description used to modify or describe a noun
        Enter your amazing code here!
    */
  // __Name__ is a __adjective__ __noun__. They are always __adverb__ __verb__.

String name = console.readLine("Enter a name: "); String adjective = console.readLine("Enter an adjective: "); String noun = console.readLine("Enter a noun: "); String adverb = console.readLine("Enter an adverb: "); String verb = console.readLine("Enter a verb ending with -ing: ");

console.printf("Your TreeStory:/n------------\n"); console.printf("%s is a %s %s. ", name, adjective, noun); console.printf("They are always %s %s.\n", adverb, verb);

Then I run it (by clicking Enter) and get this message: TreeStory.java:22: error: reached error at end of file while parsing console.printf("They are always %s %s.\n", adverb, verb);

The error message points above the last parenthesis. I hope this helps.

// Name is a adjective noun. They are always adverb verb. String name = console.readLine("Enter a name: "); String adjective = console.readLine("Enter an adjective: "); String noun = console.readLine("Enter a noun: "); String adverb = console.readLine("Enter an adverb: "); String verb = console.readLine("Enter a verb ending with -ing: ");

console.printf("Your TreeStory:/n------------\n");

console.printf("%s is a %s %s. ", name, adjective, noun);

console.printf("They are always %s %s.\n", adverb, verb);

Sure I'll try it. Yes, Mr. Craig Dennis. I also launched a brand new workspace for that particular exercise and the ran it. I received the same error message.

So I just closed a curly bracket ( } ) after the.........verb);

I received the same error message. I completed the working prototype stage regardless but was having trouble with this particular task.

I did just that. No luck https://teamtreehouse.com/workspaces/7147612

I don't know what it could be. I launched a brand new workspace for that particular exercise and the ran it. I received the same error message.

I think only you can access your own workspace links.

I had another look at your error code and it indicates that the problem is on line 22.

If you have received any emails from Mr. Craig you could email back to him with the code. He may be able to help.

I am following the discussion so if you have any more information you could post it and I would see it (as well as anyone else). If I get any more info I will let you know. I am not stopping, I just don't have any more ideas at the moment, as I said if I get any more info I will let you know. (I will still be working on my projects on treehouse, so I will get a notification if you post anything)

I have the browser open. Does that not let you get in?

No it doesn't.

OK sounds good. I moved onto the next Stage, launched a new workspace and tried to run the new code and that same error keeps coming up. I inserted the same info Mr. Dennis did into my workspace, I don't get it?

Thanks for all the help!

No Problem, I'll still be around.