Results 1 to 3 of 3
  1. #1
    mickylad is offline Member
    Join Date
    Nov 2011
    Posts
    11
    Rep Power
    0

    Default Properties: NullPointException

    Hey guys,

    I'm trying to assign a String the value of a property key-value pair but I get a NullPointerException when I try to run the code.

    The method, part of the HTTPThread class, is:

    Java Code:
    187    public void statusline(String version, int codeIn) {
    188        
    189        String code = Integer.toString(codeIn);
    190        String reason = WebServer.responsecodes.getProperty(code);
    191        
    192        if(reason == null) {
    193            
    194            code = "500";
    195            reason = "Internal Server Error";
    196        }
    197        
    198        writer.print(version + " " + code + " " + reason + "\r\n");
    199    }
    These properties are initiated in the WebServer class like this:

    Java Code:
    44        try {
    45            
    46            responsecodes = new Properties();
    47            responsecodes.load(new FileInputStream("properties"+separator+"responsecodes.properties"));
    48            
    49        } catch(IOException e) {
    50            
    51            // Couldn't read response codes
    52            System.out.println("Error: couldn't read response codes");
    53        }
    The properties are loaded correctly because I can access them inside the WebServer class.

    My stack trace (tester just runs HTTPThread):

    Java Code:
    debug:
    Exception in thread "main" java.lang.NullPointerException
    	at server.HTTPThread.statusline(HTTPThread.java:190)
    	at server.HTTPThread.run(HTTPThread.java:87)
    	at server.tester.main(tester.java:20)
    Java Result: 1
    BUILD SUCCESSFUL (total time: 0 seconds)

  2. #2
    mickylad is offline Member
    Join Date
    Nov 2011
    Posts
    11
    Rep Power
    0

    Default Re: Properties: NullPointException

    I also get a NullPointerException for other operations that I assumed would work fine, such as:

    Java Code:
    while((header = reader.readLine()) != null) {
    ...
    }
    Why would this be? Is it something to do with how threads handle null values?

  3. #3
    mickylad is offline Member
    Join Date
    Nov 2011
    Posts
    11
    Rep Power
    0

    Default Re: Properties: NullPointException

    This has fixed itself, but I have no idea why. I would still appreciate it if anyone could shed some light on it for future reference.
    Cheers.

Similar Threads

  1. Properties
    By Winarto in forum XML
    Replies: 0
    Last Post: 08-29-2008, 04:32 PM
  2. properties help me please
    By Winarto in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 08-29-2008, 01:42 PM
  3. Getting .mp3 properties
    By Leprechaun in forum New To Java
    Replies: 1
    Last Post: 02-06-2008, 06:55 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •