• Post Reply Bookmark Topic Watch Topic
  • New Topic

Null pointer execptions  RSS feed

 
Adam Juszczyk
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am also in interest in java but it does not work for me. I use IntelJ as compiler. I also want to do this boring console appp but. I read I can use Console class for this but when I try to compile my code with it I get NullExeption. Help?
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you read the javadoc for the console class ?
As it explains there, depending on how the JVM is being run, there may be no console, in which case the System.console() method (I assume that's how you are trying to access the console) will return null.
One of the scenarios where a Console will not exist is if you try to run your program from an IDE. Try running it from the command line instead and see if that helps.
 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, Console is a wonderful class. You can use it at the command line and as soon as you package your app in a .jar file, Console ceases to work
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ponury Żniwiarz wrote:I use IntelJ as compiler.

Do you mean IntelliJ? That is not a compiler, but an IDE (Integrated Development Environment).

About your NullPointerException: It would be much easier to help us if you show us your source code, and the exact error message that you get. Note that with an exception, you usually get a stack trace, that tells you exactly in which line of your program the exception happened.

A NullPointerException happens when you try to call a method or access a member variable of an object on a variable that is null. You'll have to make the variable refer to an object before you try to call methods or access member variables on it.
 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You never get that Exception when you compile the code. You often get it when you try to execute the code.
 
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!