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
David Schriver
3,707 PointsWorks fine in workspace, but gives me a "NullPointerException" error in Notepad ++.
While the code works on the website Notepad++ seems to have trouble with the Console object. I looked up other tutorials and got a work around through a Scanner object and System.out, but it would be nice if I could use the original Console object in step with the tutorials. Any Ideas on how to make it work? Here's my code:
import java.io.Console;
import java.util.Scanner;
public class Introductions {
public static void main(String[] args) {
/*
Console console = System.console();
// Welcome to the Introductions program! Your code goes below here
String name = console.readLine("Who are you? ");
console.printf("Eat my turds, %s!",name);
*/
Scanner inpoot = new Scanner(System.in);
System.out.print("Who are you? ");
String name = inpoot.next();
System.out.format("Eat my turds, %s!", name);
} }
Solution (from James Simshaw): It works in Windows command prompt but not the Notepad ++ plugin. go figure.
1 Answer
James Simshaw
28,738 PointsHello,
I haven't used Notepad++ for Java yet, but it sounds like its causing the error because Notepad++ likely doesn't have console support similar to running the code inside Eclipse. If you saved the file, then in a terminal, run:
javac Introductions.java
java Introductions
and see if that works?
David Schriver
3,707 PointsDavid Schriver
3,707 Points"javac Introductions.java java Introductions" Doesn't work as one line. I've been using "javac [filename].java" then "java [filename]", which works for me. The file complies as usual but gives me the "NullPointerException" error when I try to run it while using the Console object.
James Simshaw
28,738 PointsJames Simshaw
28,738 PointsSorry about the formatting of the commands, I had meant for them to be on two seperate lines. I've tried running your code and both the commented and uncommented sections work for myself. Opps, forgot Notepad++ was windows only. I'll have to look deeper, but it seems like there's something setup different with your environment. What version of Java have you installed?
James Simshaw
28,738 PointsJames Simshaw
28,738 PointsAlso, which terminal in Windows did you use, the command prompt(cmd.exe) or powershell?
David Schriver
3,707 PointsDavid Schriver
3,707 PointsNotepad ++ has its own command prompt plugin. But since you mentioned it, I gave it a shot in Windows command prompt instead and it worked. Thanks!
James Simshaw
28,738 PointsJames Simshaw
28,738 PointsYou're welcome. Glad you were able to get it sorted out. Good luck with Java.
Nicolas Hampton
44,725 PointsNicolas Hampton
44,725 PointsI believe you still have to put the && operator between the two separate commands on the command line for the terminal to chain them together.