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

Nika Zurashvili
Nika Zurashvili
305 Points

What is the reason behind this error when compiling a Java code via the console?

Hi,

As you might have already guessed, I'm very new to coding and Java, so I'm following Craig Dennis' tutorials.

I'm currently on the second video "Strings and Variables" and when I try to compile my work via the console I get this error:

" Picked up JAVA_TOOL_OPTIONS: -Xmx128m
Picked up _JAVA_OPTIONS: -Xmx128m
Introductions.java:10: error: reached end of file while parsing
}
^
1 error "

Can you guys help me with this? It's holding me back from progressing further into the course. Thanks!

12 Answers

Juraj Sallai
Juraj Sallai
7,188 Points

Probably just missing { or }. It happens when you dont properly close the class.

Nika Zurashvili
Nika Zurashvili
305 Points

No, actually. The code is so simple, it'd be too hard to miss a 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 Nika");      
    console.printf("Nika is learning how to write Java");

} "

Do you think I've forgotten to end a code or something?

This is what the console outputs if I try to compile (using the following: javac Introductions.java) the code above:

"
treehouse:~/workspace$ javac Introductions.java <--- This is how I try to compile the code.
Picked up JAVA_TOOL_OPTIONS: -Xmx128m
Picked up _JAVA_OPTIONS: -Xmx128m
Introductions.java:10: error: reached end of file while parsing
}
^
1 error "

Juraj Sallai
Juraj Sallai
7,188 Points

Yes it seems you are missing } at the end of your code. You need to close class and also main method.

Nika Zurashvili
Nika Zurashvili
305 Points

Okay! So, I edited the code and put a "}" at the end.

This is what it looks like now:

" 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 Nika");      
    console.printf("Nika is learning how to write Java");
}

} "

But still, the same error is displayed when compiling the code.

Here it is:

" treehouse:~/workspace$ javac Introductions.java
Picked up JAVA_TOOL_OPTIONS: -Xmx128m
Picked up _JAVA_OPTIONS: -Xmx128m
Introductions.java:10: error: reached end of file while parsing
}
^
1 error
"

Need help.

Juraj Sallai
Juraj Sallai
7,188 Points

Are you sure you saved changes in Workspace?

Juraj Sallai
Juraj Sallai
7,188 Points

Strange, I am nôt getting that 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("Hello, my name is Nika");      
    console.printf("Nika is learning how to write Java");
  }
}
Nika Zurashvili
Nika Zurashvili
305 Points

Gosh... What should I do? I messaged the staff, so hopefully they can help me out.

Craig Dennis
Craig Dennis
Treehouse Teacher

Hi Nika Zurashvili !

Can you create a workspace snapshot for me please? At the top of the workspace window there is a camera. It will create a link that will let me see your workspace.

Thanks!

Craig Dennis
Craig Dennis
Treehouse Teacher

Here's the output as I got it. Are you seeing something different?

treehouse:~/workspace$ javac Introductions.java                                 
Picked up JAVA_TOOL_OPTIONS: -Xmx128m                                           
Picked up _JAVA_OPTIONS: -Xmx128m                                               
treehouse:~/workspace$ java Introductions                                       
Picked up JAVA_TOOL_OPTIONS: -Xmx128m                                           
Picked up _JAVA_OPTIONS: -Xmx128m                                               
Hello, my name is NikaNika is learning how to write Java
Nika Zurashvili
Nika Zurashvili
305 Points

Thing is that I’m seeing the Xmx messages but not the ‘Nika is learing’ message.

Craig Dennis
Craig Dennis
Treehouse Teacher

Are you sure? The prompt is showing up after that line......you are missing the new lines so it's all on one line.

Craig Dennis
Craig Dennis
Treehouse Teacher

And you've written javac Introductions.java to compile and then java Introductions to run?

Nika Zurashvili
Nika Zurashvili
305 Points

Oh gosh! No, that’s what I forgot to do! I forgot to run it after compiling. Thanks Craig!

Craig Dennis
Craig Dennis
Treehouse Teacher

Common mistake! Glad we tracked it down!

Stick with it! ??

Nika Zurashvili
Nika Zurashvili
305 Points

Thanks Craig and I will! By the way, you’re tutorials are really easy to understand! Good job and thanks, never thought I’d even manage to write a single line of code, lol

Nika Zurashvili
Nika Zurashvili
305 Points

Yeap! I don’t get that message in the console. Feels kind of discouraging. Already wasted 2 days of my trial because of this :/

Nika Zurashvili
Nika Zurashvili
305 Points

Craig Dennis , I was able to progress further into the course but I still get those Xmx messages before what I actually want to get in the console. Is this normal? Am I doing something wrong? Because I don't see similar thing happening to you in those tutorials.