This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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:
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: