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

package test;

import java.io.Console;


    public class test{

        public static void main(String [] args){
          Console console = System.console();
            String Response ;
            boolean No;
            do {
(this is line 13)   -->  Response = console.readLine("Do you understand do while loops?");
              No = (Response.equalsIgnoreCase("no"));
              if(No){
                console.printf("try again.");
              }
            }
            while(No);
        }
    }

after typing the follwing code i got this message in the console(using eclipse)


"... Exception in thread "main" java.lang.NullPointerException at test.test.main(test.java:13) ... "

Can anyone explaine why? thanks :)

Hey Tal,

how can we help you???

Should I go through every line of the code above?

Let me know !

Grigorij

3 Answers

Craig Dennis
STAFF
Craig Dennis
Treehouse Teacher

Don't worry about the class wrapper. Just do the inner parts inside the main method. I've imported console for you as well, so don't worry about creating it.

We'll go over all the wrapper parts in Java Objects.

Your logic looks pretty good. Let me know if you are still having problems after removing the wrapper!

Hope it helps!

The compiler prompt an error message for line 13.. I marked it in the code so it would be easy to find and this is the error message: "... Exception in thread "main" java.lang.NullPointerException at test.test.main(test.java:13) ... "

Hi tal,

sorry for the delay.

I know that using Console inside IDE like Eclipse as a pain. Eclipse tries to read Input from the keyboard and give Output through Console, but IDE is not using console like a console application written in a texteditor.

I have modified your code in IntellyJ and it works superp:

import java.util.Scanner;

public class Test {

        public static void main(String [] args){
            Scanner s = new Scanner(System.in);
// Scanner is a great replacement for console if you are in IDE 
            String Response;
            boolean No;
            do {
                System.out.println("Do you understand do while loops?");
                Response = s.nextLine();
                No = (Response.equalsIgnoreCase("no"));
                if(No){
                    System.out.println("try again.");
                }
            }
            while(No);
        }
    }

I hope it helps a little bit

Grigorij

thank you Grigori! i really appriciate it!