• Post Reply Bookmark Topic Watch Topic
  • New Topic

why readLine method of System.Console is throwing NullPointerException  RSS feed

 
amit kumararya
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone, can anyone please let me know why the following code compiles fine but gives the following error at runtime.
Exception in thread "main" java.lang.NullPointerException
at practice.ColsoleTest.main(ColsoleTest.java:13)



I will be very grateful for any help.
 
Surendra Kumar
Ranch Hand
Posts: 236
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried this program and did not get any run-time exception.
All it does is to take the input from console and print back.

How're you running it? From IDE like Eclipse?

Try from command line and enter some text and it prints back.
 
amit kumararya
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes i am doing from eclipse.
thanks a lot for pointing this out.

can you please explain why so.

--
amit
 
Surendra Kumar
Ranch Hand
Posts: 236
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eclipse does not support interactive console.

(Use System.in instead)
 
amit kumararya
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you very much...
 
amit kumararya
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
also, can you please tell me the complete declaration of how to use system.in.

just tell me the object declarations, i will be able to go ahead from there.

Thank you.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
amit kumararya wrote:also, can you please tell me the complete declaration of how to use system.in.

The fact is that most people rarely use it directly - although there's nothing to stop you doing so - it's usually wrapped in a more user-friendly object like a Scanner (java.util.Scanner). This page, for example, shows you how to get console input using a BufferedReader, but personally, I'd advise reading the tutorial chapter on I/O because that will give you a much more comprehensive explanation on how streams work in Java.

Winston
 
amit kumararya
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you very much....
 
Robert D. Smith
Ranch Hand
Posts: 221
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Simply because I came across it first, and it's simple enough to use, I tend to use the Scanner object for my user input.



replace with nextInt, etc. as the need arises.

Robert
 
amit kumararya
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
wow, this is wonderful.

thanksssss a lotttt.....
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!