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 - problem with method

Hello,

At workspaces I can start java Introductions.java without problems - printf("Hello"), when I am at Intellij IDEA and start java Introductions.java: NullPointerException. Where is the problem?

Thanks.

Can you share your code for the file?

import java.io.Console;

public class Introductions {

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

1 Answer

Here is what I would use.

public class Introductions {

    public static void main(String[] args) {
        System.out.println("Hello!");
    }

}

There is even a shortcode. Type 'sout' and then press <tab> and it will type it for you.

I have programmed 2 years in Java, System ... is shorter solution, but I want to know, why is problem, when I use Console bla bla :-)