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

Android

What's wrong with this program?

This simple program that I learned in the first videos here will not run in Eclipse. Am I missing something??

import java.io.Console;

public class LotsOfWords {

public static void main(String[] args) {
    // Test program.  Why will console not work here?

    Console console = System.console();

    String thisThing = "program";
    console.printf("This is the first line of the %s\n", thisThing);
    console.printf("Here is another line in the %s\n", thisThing);


}

}

It gives me this error in the console:

Exception in thread "main" java.lang.Error: Unresolved compilation problem: The method printf(String, Object[]) in the type Console is not applicable for the arguments (String)

at LotsOfWords.main(LotsOfWords.java:9)

Thanks a bunch

1 Answer

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Greg;

Eclipse does not have a great, or any, implementation of the Console class. If you want to build the projects in Eclipse, look into the Scanner class, which is similar and is support tree d by Eclipse.

Post back with additional questions.

Ken

Thank you, do you guys cover the scanner class in later lessons? I have not learned that yet.

Ken Alger
Ken Alger
Treehouse Teacher

Greg;

Thus far the Scanner class has not been officially covered. Eclipse is on the course roadmap, not sure of an exact timeline, but it is on the list.

Take a look at the docs and with a few minor changes implementation should be straightforward.

Happy coding.

Ken