Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Giving runtime error

 
orgil khatanbaatar
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15483
43
Android IntelliJ IDE Java Scala Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please copy and paste the exact error message. Error messages contain a lot of information that help you to find the source of the problem - it's important to learn to read and understand error messages. And by telling us exactly what the error message is, you're making it a lot easier to help you.

Note that if you write code like this:

you will never know what went wrong if an exception happens.

Change your code to this, so that you can at least see what the error is:

 
orgil khatanbaatar
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Exception in thread "main" java.lang.NullPointerException
at Fileclass.readFile(Fileclass.java:12)
at Fileclass.main(Fileclass.java:24)
 
orgil khatanbaatar
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
above is the error given.
please any solution?
 
Rob Spoor
Sheriff
Pie
Posts: 20665
65
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
PatienceIsAVirtue.

Your Scanner field x remains null because you shadow it with a local variable inside the openFile method. Remove the Scanner type from the line where you initialize x and it will use the field instead:
 
orgil khatanbaatar
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you! that is correct.
 
Rob Spoor
Sheriff
Pie
Posts: 20665
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic