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 Basics Using your New Tools Multiple Strings

Error: class, interface, enum expected

import java.io.Console;

public class TreeStory {}

    public static void main(String[] args) {}

      Console console = System.console();



     // __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);

Above is what my whole program looks like. This is the error I am getting:

" String verb = console.readLine("Enter a verb ending with -ing: ");
^
TreeStory.java:17: error: class, interface, or enum expected
console.printf("Your Treestory:\n-------\n");
^
TreeStory.java:18: error: class, interface, or enum expected
console.printf("%s is a %s %s. ", name, adjective,noun);
^
They there are 9 errors all seeming to have something to do with the first letter of every line"

1 Answer

Stephen Bone
Stephen Bone
12,359 Points

Hi Jamar

I haven't gone through it line by line but you open and then immediately close your class after declaring it on the second line. It should be that you open it with the curly brace with all of your code inside of it and then have the closing curly brace after it (at the end).

EDIT: And I've just noticed you've done the same with the main method too.

So you've currently got:

import java.io.Console;

public class TreeStory {}

public static void main(String[] args) {}
Console console = System.console();
...

When it should be as below: (Note the placement of the closing braces)

import java.io.Console;

public class TreeStory {

    public static void main(String[] args) {
        Console console = System.console();
        ...
    }
}

Hope it helps!

Stephen

Thanks Stephen, I appreciate the help. That fixed the issue.