File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes getResourceAsStream() +NullPointerException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "getResourceAsStream() +NullPointerException" Watch "getResourceAsStream() +NullPointerException" New topic
Author

getResourceAsStream() +NullPointerException

Elizabath Lima
Ranch Hand

Joined: Nov 23, 2005
Posts: 32
Hi..

I'm having a strange problem.

Properties props = new Properties(); props.load(this.getClass().getResourceAsStream("/myapp.properties"));
driver=props.getProperty("dbdriver");
url = props.getProperty("dburl");
userName = props.getProperty("dbuser");
password = props.getProperty("dbpass");

this gives the following exception in tomcat. I placed the properties file directly under 'myapp' directory which s under webapp. How i can give path of propfile?

java.lang.NullPointerException
at java.util.Properties$LineReader.readLine(Properties.java:365)
at java.util.Properties.load(Properties.java:293)
at org.nmn.DBConn.getConnection(DBConn.java:23)

Thanks in advance
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Try dropping it on the WEB-INF/classes directory so that it can be found on the application classpath
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: getResourceAsStream() +NullPointerException
 
Similar Threads
getting the value of .properties file
Problem in Locating a properties File (Not the Struts application.properties)
Problem with static block and getResourceAsStream
Stackoverflow without recursion
How to get the path of property file.