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


Please help me with this Error

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!
  String ageIntToString = console.readLine("What is your age?  ");
  int age = Integer.parseInt(ageIntToString);
  if (age < 13) {
    //Inser Exit Code
    console.printf("Sorry you must be at least 13 to use this program. \n");
   String name = console.readLine("Enter a name:  ");
   String adjective = console.readLine("Enter an adjective:  ");
  String noun;
  boolean invalidWord;

  do {

   noun = console.readLine("Enter a noun:  ");
     invalidWord = (noun.equalsIgnoreCase("dork")||
  if (invalidWord) {
    console.printf("That type of language is not allowed. Try Again . . .\n");
  } while(invalidWord);
  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. They are always %s %s.\n",name,adjective,noun,adverb,verb);


There is an error saying "Illegal Start of Type". I can't understand where my code is wrong. Thanks in advance.

1 Answer

I couldn't find any mistakes in your code, after compiling it, it ran fine for me and did what it was expected to do.

Your code can really be cleaned up to be more readable. I'm not sure if this was intentional or not, but, I would remove the exit statement in your if-statement code block.

My last bit of advice would be to catch the NumberFormatException that can occur while parsing the age as a string variable into an int variable.

Thank you so much! It helped.