• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting nullpointerexception while using getResourceAsStream

 
Karthik Krishnamurthy
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author
Saloon Keeper
Posts: 4014
18
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Karthik Krishnamurthy
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Scott.
I basically re-set my whole environment and it worked.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic