Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java

Kelvin Warui
PLUS
Kelvin Warui
Courses Plus Student 878 Points

java.lang.nullPointerException

Hi i have done the code challenge for the string formating using the printf() method and passed.I am trying to do the same on my netbeans ide but i have an exception called java.lang.nullPointerException.I have capitalize S in the keyword String and initialized it i dont see why am getting an exception.My code looks like this

public class Introductions {




public static void main(String[] args) {

    Console console = System.console();
    String name = "Kelvin";
    console.printf("%s is my name ", name);
}

}

1 Answer

Florian Tönjes
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Florian Tönjes
Full Stack JavaScript Techdegree Graduate 50,856 Points

Hi Kelvin,

the console is usually not working in IDEs. Use System.out instead.

public static void main(String[] args) {

    String name = "Kelvin";
    System.out.printf("%s is my name ", name);
}

Kind Regards, Florian

Kelvin Warui
Kelvin Warui
Courses Plus Student 878 Points

Thank you very much ,been scratching my head all day wondering what am missing