1
public class SupplierCalculatorApplet extends JApplet{
...
public void init(){
    loadProperties();
    ...
}   

...

private void loadProperties() {
    language = "en-us";//getParameter("Language");
    prop = new Properties();
            try {
                URL urlToProps = this.getClass().getResource("config/" + language + ".properties");
                prop.load(urlToProps.openStream());//Exception Caught Here
            } catch (IOException e) {
            }   
}

Exception is found at the line indicated above. Whether language is a valid properties file or not, I catch the same exception on the same line.

3
  • 1
    Please post code and Exception. My guess is it is not finding the properties file at all. Are you loading it via ClassPath or file system? Commented Jan 12, 2012 at 17:00
  • Looking at your code (language based name to read in some properties) you might consider switching to use ResourceBundle instances instead of properties Commented Jan 12, 2012 at 17:07
  • 1
    Edited. The idea is that I can load the properties file from inside the jar. I am using properties files to localize labels in the applet. Commented Jan 12, 2012 at 17:20

2 Answers 2

4

You haven't given us a lot to work with there, but my guess would be that urlToProps is null, since Class#getResource returns null if the resource isn't found, but you have no defensive check in the pictured code. So the urlToProps.openStream() part would throw an NPE.

Sign up to request clarification or add additional context in comments.

5 Comments

If the resource exists in the appropriate location, why isn't it found?
@unmuse: Have you checked whether urlToProps is null? That's the first thing to do.
It is null when load() is called.
When changed to prop.load(this.getClass().getResourceAsStream("/config/" + language + ".properties")); it works.
@unmuse: There you go. You might want to post that as an answer (it's perfectly fine to answer your own question on SO). The site will allow you to accept your own answer in two days. Could be useful to others in the future.
2

Change to:

prop.load(this.getClass().getResourceAsStream("/config/" + language + ".properties")); 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.