0
File file = new File(getClass().getResource(filePath + "/createFile.xml").toURI());

I get an error of java.lang.NullPointerException in above line. Here filePath is string variable in which I have set my directory path from where I want to read file.

3
  • 1
    Why don't you write the code simply just like this: new File(filePath+"/createFile.xml");? Commented Oct 8, 2014 at 7:36
  • @ntalbs You have to use getResource if you want to load a file from a jar. For normal files your way is much cleaner. Commented Oct 8, 2014 at 7:50
  • I have try like "new File(filePath+"/createFile.xml");" and It's read content successfully, but when I pass this data, I got same errorr in last line of below code. File file1 = new File(filePath + "\\createFile.xml"); Container container = importController.importFile(file1); container.getLoader().setEdgeDefault(EdgeDefault.DIRECTED); Commented Oct 8, 2014 at 9:28

1 Answer 1

1

Class.getResource() will return null when the resource was not found. You always should test for that before using it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.