problem on loading a XML file using Class.class.getResourceAsStream method

Posted on 2004-04-19
Medium Priority
Last Modified: 2012-08-14
I'm trying to create an InputStream for reading data from a XML file using the following statement :
InputStream in = Class.class.getResourceAsStream(XML_FILE);
This is being done within a static synchronized method.

I am getting the following exception message :-

[19/04/04 14:12:04:391 BST] 6f9fd8e7 WebGroup      E SRVE0026E: [Servlet Error]-[Generic Application Error: RemoteException occurred in server thread&#59; nested exception is:
      java.rmi.RemoteException: &#59; nested exception is:
      java.lang.ExceptionInInitializerError]: java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
      java.rmi.RemoteException: ; nested exception is:
java.rmi.RemoteException: ; nested exception is:
java.lang.ExceptionInInitializerError: java.lang.IllegalArgumentException: InputStream cannot be null
rethrown as test.intranet.exception.ApplicationError: Generic Application Error: RemoteException occurred in server thread; nested exception is:
      java.rmi.RemoteException: ; nested exception is:

I have used the this.getClass().getResourceAsStream(XML_FILE) statement within another class (not in a static method) and this worked fine.  

I wonder if anyone could shed light on my problem ?
Question by:papillon2
  • 3
LVL 86

Expert Comment

ID: 10859695
You don't want the Class class. You want the main class class, i.e. getClass().getResourceAsStream
LVL 86

Accepted Solution

CEHJ earned 765 total points
ID: 10859706
i.e. if your main class is called 'X' then you need

LVL 86

Expert Comment

ID: 10860182

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question