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 Strings and Variables

Kevin Luxmore
Kevin Luxmore
895 Points

Learning in Eclipse

I'm trying to do the first exercise in Eclipse rather than the Workspace on the website since I need to learn how to use it anyway, but when I run code I get

"Exception in thread "main" java.lang.NullPointerException at Introductions.main(Introductions.java:8)"

Aaron Arkie
Aaron Arkie
5,345 Points

Hello are you talking about the first challenge or the entire lesson in general when writing code in eclipse?

The compiler is telling you that it is finding an error in the main thread which is:

public static void main(String [] args){ // error is in here

}

After digging around the web iv'e read that System.console always throws null. Unfortunately, to use this class it would involve more code. If you are a beginner to java it would be better to use the Scanner class instead. In any case if you want to see where i found this info click here StackOverFlow

Here is my code using the Scanner class.

package treehousepackage;

import java.util.Scanner;
import static java.lang.System.out;


public class Introductions {

    public static void main(String[] args) {

        Scanner s = new Scanner(System.in);  // make scanner object
        out.print(" Please print your name:  "); // printed statement in console
        String name = s.nextLine(); // this is where it accepts input
        out.println("Your name is: " + name); // prints string and string variable


    }

}

1 Answer

if u want to work with Eclipse or NetBeans
u must first learn about basic of methods and class how to write it . like the main method if u don't write it, the app will not run and u will face errors about this .