I am working in a project and I need a resource in it. I am trying to get it using this code:
InputStream is =
JSONParser.class.getResourceAsStream("a.json");
String jsonTxt = IOUtils.toString( is );
The file a.json is located in the main file of the project.
The exact problem is:
Exception in thread "main" java.lang.NullPointerException
at java.io.Reader.<init>(Reader.java:61)
at java.io.InputStreamReader.<init>(InputStreamReader.java:55)
at org.apache.commons.io.IOUtils.copy(IOUtils.java:1049)
at org.apache.commons.io.IOUtils.toString(IOUtils.java:359)
at com.playence.parser.JSon.main(JSon.java:28)
Debugging, I saw that variable ‘is’ is null, and I guess that is why NullPointException, bugt I don’t know how to solve it.
Any help?
Thans in advance.
Finally I found my problem and I solved it.
It was related with my Eclipse configuration:
Project – propperties – Source
There I had in Myproject/src/main/resources Exclude **.
So the files in that directory wasn’t in classes. I solved it just putting Exclude (None).
Now everything is ok.
Thank you anyway!