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 Getting Started with Java IO

Stucking here

String firstName = console.readLine ("First name? "); String lastName = console.readLine (" last name? "); console.printf("First name: %s", firstName); console.printf("Last name: %s", lastName);

3 Answers

Tonnie Fanadez
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Tonnie Fanadez
UX Design Techdegree Graduate 22,796 Points

Hello Md. Jafrin Hossain

I checked the code that you provided above and it works just fine when I tested every line.

Anyway here is my code which is similar to yours.

String firstName =console.readLine ("what is your first name?");
String lastName =console.readLine ("what is your first name?");
console.printf("First name: %s", firstName);
console.printf("Last name: %s", lastName);

Thank you so much for the reply Tonnie Fanadez . Would you kindly help me in the following section

Code in my ide(eclipse):

package treehouse; import java.io.*;

public class Chechk { public static void main(String[] args) { String fn = "Jafrin"; System.out.println(fn);

    Console console = System.console();
    String name = console.readLine("Enter your name ");     
    String adjective = console.readLine("Enter an adjective ");
    console.printf("%s is very %s", name, adjective);


}

}

output: Exception in thread "main" java.lang.NullPointerException at treehouse.Chechk.main(Chechk.java:10) Jafrin

Why it shows NullPointerException?

Tonnie Fanadez
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Tonnie Fanadez
UX Design Techdegree Graduate 22,796 Points

Hi Md. Jafrin Hossain

Instead of working with console object please replace it with Scanner Object for Eclipse IDE. You will also need to import the Scanner Object using this line _ import java.util.Scanner; _

// Console console = System.console(); remove the Console Object and replace it with Scanner
   Scanner scanner = new Scanner(System.in);
   System.out.println("Enter your name");
    String name = scanner. nextLine(); 
System.out.println("Enter an adjective");
    String adjective = scanner. nextLine(); 
   System.out.printf("%s is very %s", name, adjective);

Please let me know if this helps

Thank you so much for your help brother.

Yes, I have got it.