aspose file tools*
The moose likes Beginning Java and the fly likes Giving runtime error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Giving runtime error" Watch "Giving runtime error" New topic
Author

Giving runtime error

orgil khatanbaatar
Greenhorn

Joined: Aug 05, 2011
Posts: 17
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14104
    
  16

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:


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
orgil khatanbaatar
Greenhorn

Joined: Aug 05, 2011
Posts: 17
Exception in thread "main" java.lang.NullPointerException
at Fileclass.readFile(Fileclass.java:12)
at Fileclass.main(Fileclass.java:24)
orgil khatanbaatar
Greenhorn

Joined: Aug 05, 2011
Posts: 17
above is the error given.
please any solution?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19670
    
  18

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:


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
orgil khatanbaatar
Greenhorn

Joined: Aug 05, 2011
Posts: 17
Thank you! that is correct.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19670
    
  18

You're welcome.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Giving runtime error