user3902398
user3902398

Reputation: 1

Getting null pointer exception In FILE class

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.

Upvotes: 0

Views: 292

Answers (1)

Thirler
Thirler

Reputation: 20760

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

Upvotes: 1

Related Questions