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.

unmuse
  • 677
  • 2
  • 9
  • 21
  • 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? – JustinKSU Jan 12 '12 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 – Robin Jan 12 '12 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. – unmuse Jan 12 '12 at 17:20

2 Answers2

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.

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
  • 1
    If the resource exists in the appropriate location, why isn't it found? – unmuse Jan 12 '12 at 17:21
  • 1
    @unmuse: Have you checked whether `urlToProps` is `null`? That's the first thing to do. – T.J. Crowder Jan 12 '12 at 17:22
  • It is null when load() is called. – unmuse Jan 12 '12 at 17:31
  • 1
    When changed to prop.load(this.getClass().getResourceAsStream("/config/" + language + ".properties")); it works. – unmuse Jan 12 '12 at 17:35
  • 1
    @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. – T.J. Crowder Jan 12 '12 at 17:54
2

Change to:

prop.load(this.getClass().getResourceAsStream("/config/" + language + ".properties")); 
unmuse
  • 677
  • 2
  • 9
  • 21