Solved

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

Posted on 2004-04-19
3
658 Views
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.lang.ExceptionInInitializerError
java.rmi.RemoteException: ; nested exception is:
      java.lang.ExceptionInInitializerError
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:
      java.lang.ExceptionInInitializerError

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 ?
0
Comment
Question by:papillon2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
3 Comments
 
LVL 86

Expert Comment

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

Accepted Solution

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

X.class.getResourceAsStream
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10860182
8-)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

695 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