Results 1 to 7 of 7
Thread: Using Console Class
- 08-13-2011, 02:04 PM #1
Using Console Class
I am having a little trouble using the Console class. I imported the class as well as read on the methods that I need to complete the job. However, it keeps giving a Null Pointer exception.
Console console = System.console(); String username = console.readLine("User: ");
at Next_Palindrome.NextPalindrome.main(NextPalindrome .java:11)
Java Result: 1
Any ideas? This is all the code that is running btw.
- 08-13-2011, 02:18 PM #2
What variable is null? Can the console() method run a null value? What does the API doc say?
How and where are you executing the program?
- 08-13-2011, 02:46 PM #3
It catches the exception at:Java Code:
String username = console.readLine("User: ");
I am executing the program using the Netbeans IDE on a Windows PC.Tabish Chasmawala
- 08-13-2011, 03:43 PM #4
Print out the value of the console variable to see if it is null.
Did you read the API doc for the System class's console() method?
The console() method passes a null exception if the end of stream has been reached
Last edited by Norm; 08-13-2011 at 03:45 PM.
- 08-13-2011, 06:48 PM #5
I tried printing out the value of the console variable using this code:
Console console = System.console(); System.out.println(console); System.out.println(console.toString());Tabish Chasmawala
- 08-13-2011, 06:50 PM #6
Never mind... I did a little more searching and found my answer.
Stupid Java Tricks » Using the New java.io.Console Class
Thanks for the help tho.Tabish Chasmawala
- 08-13-2011, 10:34 PM #7
- By thiagohe in forum Advanced JavaReplies: 7Last Post: 08-01-2011, 01:30 PM
- By Pooja Deshpande in forum New To JavaReplies: 4Last Post: 04-25-2008, 05:51 AM
- By Java Tip in forum Java TipReplies: 0Last Post: 03-12-2008, 11:24 AM
- By Java Tip in forum Java TipReplies: 0Last Post: 01-18-2008, 11:52 AM
- By hey in forum New To JavaReplies: 10Last Post: 12-11-2007, 10:11 PM