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 Coding the Prototype

Can't figure out whats wrong.

^
TreeStory.java:21: error: class, interface, or enum expected
console.printf("%s is a %s %s. ", name, adjective,noun);
^
TreeStory.java:22: error: class, interface, or enum expected
console.printf("They are always %s %s. \n", adverb, verb);
^
9 errors

5 Answers

Watch your Curly Brackets! Your code down below, edited minutely;

public static void main(String[] args) {} <-- See This?

Console console = System.console();

// Nameis 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); <--It needs to end here

Got It!!! It worked thanks alot I appreciate the help.

chris boich
chris boich
7,846 Points

The object console needs to be capitalized, like so: Console.printf("They are always %s %s. \n", adverb, verb); The Java language along with other programming languages are case-sensitive. I am not aware if any other mistakes are in your code, but this should solve your problem based on the code you posted. Also make sure that the Console object is imported at the top of the java document:

import java.io.Console;

Craig Dennis
Craig Dennis
Treehouse Teacher

I think that the import line needs to be there and you need to get the instance, maybe one is missing?

import java.io.Console;

\\ ...
Console console = System.console();
console.printf("The instance is lower cased \n");
\\...

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

I agree with Craig, however I want to reach a few lines up and ask if you're missing a curly bracket?!

If you wouldn't mind sending me a PM, if we get hose here on TreeHouse, and I'll branch out to you further?? Thanks!!

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

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

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