This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

NPE from K&B example SCJP6  RSS feed

 
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, this is an example from K&B SCJP6 page 458.
I'm getting a null pointer exception, but I'm not sure what needs to be changed.
I tried initallising the char array with char[] pw = new char[1000];
but it made no difference. Could someone explain please?



Exception in thread "main" java.lang.NullPointerException
at io_streams.ConsoleReadIn.main(ConsoleReadIn.java:11)


Thank you!
Nigel
 
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you must be running this program from eclipse or another IDE.
 
Nigel Shrin
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes - I am using Eclipse

Are you able to explain why?

Thanks
 
Sheriff
Posts: 9613
37
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
IDEs like Netbeans and Eclipse don't support the console class right now that's why they return null when you call System.console(). This might be fixed in future versions...
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Problem is:



This method returns null according to javadoc when the Workbench or Operating System does not give you a console.

I got an exception too using Eclipse and Windows. It worked fine using a MS DOS prompt.

You can at least add to your program to something like this:



I hope someone can find out how we get a valid console within Eclipse.
 
author
Sheriff
Posts: 8981
19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As always we strongly recommend that you use the command line to study for the SCJP. All of the questions in the real exam were written in a text file and compiled and run from the command line.

No IDE's were used!
 
Nigel Shrin
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Dear Ankit, Peter & Bert, THANK YOU for taking the time to reply.

Much appreciated.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!