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 trialDavid O'Mahoney
869 PointsIn Java I keep getting the error message 'error: reached end of file while parsing'
I keep getting the error message 'error: reached end of file while parsing'. I know this is to do with curly brackets but I've been trying to rectify it for over an hour now and i can't seem to. Any help would be appreciated. Link to snapshot below.
1 Answer
rydavim
18,814 PointsI am by no means a Java expert, but it looks like you just have a couple of typos and missing brackets. console
was misspelled near line 15, and you were missing a couple of closing curly brackets at the end of your file.
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!
*/
int age =12;
if (age < 13) {
console.printf("Sorry, you must be 13 years old to use this program\n"); /* fixed typo in console */
System.exit(0);
}
{
String name = console.readLine("Enter your name: ");
String adjective = console.readLine("Enter an adjective: ");
String Noun = console.readLine("Enter a Noun: ");
String Verb = console.readLine("Enter an Verb: ");
console.printf("%s is very %s", name, adjective);
}
} /* added closing brackets here */
} /* and here */
Let me know if you have any follow up questions, and I'll do my best to answer them with my limited knowledge of Java, but fixing those small errors let it compile for me without issues.
Good luck, and happy coding!
David O'Mahoney
869 PointsDavid O'Mahoney
869 PointsThank you very much for your help! I can't say I understand curly brackets still, but at least I can continue to learn with your solution! Thanks again.
rydavim
18,814 Pointsrydavim
18,814 PointsDavid O'Mahoney
So, the basics of brackets are that they need to be paired. There is always an opening bracket { and there needs to be a closing bracket } at the end of the associated block.
In this case, it looks like you never closed the class and main blocks of your code.
If you're using Workspace, if you click by a bracket it should highlight the matching opening or closing bracket. If you don't get a highlight when you click (or it's in a weird place), there's a good chance you forgot the pair that should match it.
Sorry I can't be more specific in how it relates to Java, but hopefully that gives you a better idea of how they're meant to work. Pairing some type of bracket or brace - {}, (), {} - is extremely common in programming, so these concepts are important and consistent across many languages.