Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java Java Basics Getting Started with Java Strings and Variables

Trystin May
Trystin May
1,475 Points

Error message 10: error: reached end of file while parsing } ^ 1 error

import java.io.Console;

public class Introductions {

public static void main(String[] args) {
    Console console = System.console();
    // Welcome to the Introductions program!  Your code goes below here
    console.printf("Hi, my name is TJ\n");
    console.printf("TJ is learning how to write Java\n");

}

here's what I have, but when ever I try to run it with the console it gives me the error message Introductions.java:10: error: reached end of file while parsing } ^ 1 error What might I be doing wrong?

James Merritt
James Merritt
Courses Plus Student 394 Points

console.printf("Hello, my name is James"); console.printf("James is learning to write Java"); }

I write the above and get the same issue - any ideas what I am doing wrong?

6 Answers

Trystin May
Trystin May
1,475 Points

I deleted a "}" symbol no idea what its called, but it cause the code to be left open or something. Make sure you close all your parentheses.

Tariq Khan
Tariq Khan
16,713 Points

Hi Trystin! The "}" symbol is referred to as a close curly bracket. There are also square brackets [] that you see next to the String type in the main class. All blocks of Java code must start with an open bracket { and end with a close bracket, or you will get a compile time error as happened to you when you forgot to include it in your initial code. Good for you to realize your error and correct it! It is a common error that programmers can make. One way to avoid it is to type both the opening and closing symbols right away, and then go back and enter your code. Also, remember to include a semicolon " ; " at end of all variable and array declarations.

Tariq Khan
Tariq Khan
16,713 Points

Hi James! I just saw that you were having a problem completing this step. Without seeing all the steps you took, I cannot say exactly what you might have done wrong. So I thought I would provide the exact steps that I did to complete this exercise. Also, please remember to save any changes you make to the Introductions.java file before compiling the source code with the javac Introductions.java command in the console. Finally, just to be clear the \n at the of the string in quotes starts a new line so that the output doesn't run onto one line, and do split up your two console.printf statements onto two separate lines. I hope that helps you figure out your mistake.

import java.io.Console;

public class Introductions {

public static void main(String[] args) {
    Console console = System.console();
    // Welcome to the Introductions program!  Your code goes below here
    console.printf("Hello, my name is Tariq\n"); 
    console.printf("Tariq is learning how to write Java\n");

} }

Below are the steps to complete compiling the Introductions.java source code and then running the code in the workspace console.

treehouse:~/workspace$ javac Introductions.java
treehouse:~/workspace$ java Introductions
Hello, my name is Tariq
Tariq is learning how to write Java
treehouse:~/workspace$

James Merritt
PLUS
James Merritt
Courses Plus Student 394 Points

Thanks Tariq, it turns out I had deleted a closed curly bracket from a lower line, once I added this in it worked fine. Thanks for the quick help!

Joseph Waugh
Joseph Waugh
409 Points

I have my code written perfectly and I am still continuing to receive the Introductions.java:10: error: reached end of file while parsing } message. Can anyone help?

Trystin May
Trystin May
1,475 Points

The 10 means the error is found on line 10, while the "reached end of file while parsing }" means you need to add a } to the end. You may already have one there but, you need another. All brackets need to be closed or paired with thier closing counter part ie. (){}[]<>"". to explain further if you have code like this { xxx:x "xxx"; (xxxxx)] you used the wrong closing bracket and it will give you an error say you need a } instead of ]. or you completely for got to close the curley brackets { xxx:x "xxx"; (xxxxx) so you need to add another } at the end of you code after line 10

I may have over explained but make sure all brackets have and open and closing.

Joseph Waugh
Joseph Waugh
409 Points

Thank you, your advice has helped.