This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
Hi to all,
I try to read from a file set in web.xml as a context-param
and to store into the Listener the list contained in the file as a context attribute. I get a runtime exception when I try to read the .txt file
on the line is = context.getResourceAsStream(libreria);
I get a NullPointerException.
Could you give me a suggestion? I'm not sure that the path in param-value is right, it means I'm not sure I built the package in the right location because on netbeans I obtain a package inside source packages.Do you think I need to create programmatically the File and the dir?
Please be sure to use code tags when posting code to the forums. Unformatted or unindented code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please click this link ⇒ UseCodeTags ⇐ for more information.
Properly indented and formatted code greatly increases the probability that your question will get quicker, better answers.
Well, I don't think the context is null because, if it was, then you would get a NullPointerException in the context.getInitParameter("library-file"); instruction. Also, the API says that, if the resource can't be found, then the getResourceAsStream method only returns null.
Can you please show us the stack trace? Also, as Bear already mentioned, please do not forget to use code tags when posting code to the forums.
stefania ferrarelli wrote:on the line is = context.getResourceAsStream(libreria); I get a NullPointerException.
Are you the exception is at this line. I don't think the context would be null but if the /WEB-INF/data/my-library.txt doesn't exist, then context.getResourceAsStream will return null which can result in a NullPointerException...
Thanks to all!!
I tryed to put the .txt file directly inside the root of the webapp
and now everything works.
I still cannot understand why creating a package data by netbeans and putting a file inside it didn't work. Do you think it is correct to put a file directly inside Web Pages? If I create a directory with
why I cannot find the package inside netbeans? Can I assume a package is a directory?
Sorry for not using tag code in the last post, I didn't know about it!!