This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Websphere and the fly likes Getting nullpointerexception while using getResourceAsStream Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Products » Websphere
Bookmark "Getting nullpointerexception while using getResourceAsStream" Watch "Getting nullpointerexception while using getResourceAsStream" New topic
Author

Getting nullpointerexception while using getResourceAsStream

Karthik Krishnamurthy
Ranch Hand

Joined: Feb 04, 2005
Posts: 118
Hi,
I have an application that I moved from WAS 5 to WAS 6.

I am using this command to get access to an xml file :

InputStream in = DefaultXMLBuilder.class.getClassLoader().getResourceAsStream("filename.xml");

The only difference between the 2 inzstallations is that in the earlier WAS 5 set up I was ungin PARENT_LAST class loader policy while in the new WAS 6 set up I am using PARENT_FIRST class loader policy.

It was working fine in WAS 5 but in WAS 6 I am getting a NullPointerException at this line.

Any help greatly appreciated.

Thx
Karthik
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3703
    
    5

Originally posted by Karthik Krishnamurthy:
The only difference between the 2 inzstallations is that in the earlier WAS 5 set up I was ungin PARENT_LAST class loader policy while in the new WAS 6 set up I am using PARENT_FIRST class loader policy.


Thats a non-trivial change when you are reading files from the class path. It's probable you are retrieving the wrong class loader, either one too high on the food chain (like the server's bootstrap loader) or too low.

ClassLoader's in J2EE, WebSphere in particular, are extremely complicated. If I were you I would grab the classloader object and view it in a debugger (or call toString() on it) to try to determine where on the food chain the class loader you have is, and where you need to be (up or down).

If I had to guess I'd say you are loading the "DefaultXMLBuilder" on the server (in the server's lib directory) therefore when you call getClassLoader() you are actually retrieving the server class loader which has no knowledge of files inside the EAR.


My Blog: Down Home Country Coding with Scott Selikoff
Karthik Krishnamurthy
Ranch Hand

Joined: Feb 04, 2005
Posts: 118
Thanks Scott.
I basically re-set my whole environment and it worked.
 
Consider Paul's rocket mass heater.
 
subject: Getting nullpointerexception while using getResourceAsStream
 
Similar Threads
Regadring JBoss5 Problem for VFSZIP
reading .properties file
Locating files
can I have multiple version of XML parser?
Class Loader Unable to load class