Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7730501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:14:24+00:00 2026-06-01T06:14:24+00:00

I’m using websphere and Java EE and get this error message: Exception reading propertiesfile

  • 0

I’m using websphere and Java EE and get this error message:

Exception reading propertiesfile in init java.lang.NullPointerException
java.lang.NullPointerException
    at java.io.Reader.<init>(Reader.java(Inlined Compiled Code))
    at java.io.InputStreamReader.<init>(InputStreamReader.java(Inlined Compiled Code))
    at java.util.Properties.load(Properties.java(Compiled Code))
    at se.prv.register.admin.util.MessageHandler.loadDictionary(MessageHandler.java:90)
    at se.prv.register.admin.util.MessageHandler.<clinit>(MessageHandler.java:15)

This is my code

package se.prv.pandora.arendeprocess.util;

import java.io.InputStream;
import java.util.Properties;

import org.apache.log4j.Logger;

public class MessageHandler extends AbstractTextHandler{
    private static Properties dictionary;
    private final static String dictionaryFileName="messages.properties";
    private final static String className="se.prv.pandora.arendeprocess.util.MessageHandler";
    private static Logger logger = Logger.getLogger(MessageHandler.class);

    static {
        loadDictionary();
    }

    public static void main(String[] args) {
        String str = getParameterizedMessageTest("TEST",new String[]{"PETER","GÖRAN"});
        System.out.println(str);
    }
    public static String getMessage(String key){
        return getMessage(key,true);
    }
    public static String getMessage(String key,boolean useReference){
        logger.debug("!!!! getMessage "+ key);
        if (key==null || key.length()==0){
            throw new RuntimeException("GetMessage without key");
        }
        if (dictionary==null){
            loadDictionary();
        }
        if (useReference){
            return getFullMessage(getMessage(dictionary,key));
        }
        else {
            //String str = getMessage(dictionary,key);
            //logger.debug(str);
            String str2 = getCoreMessage(getMessage(dictionary,key));
            //logger.debug(str2);
            return str2;
        }
    }
    public static String getFirstPartOfMessage(String key){
        if (key==null || key.length()==0){
            throw new RuntimeException("GetMessage without key");
        }
        if (dictionary==null){
            loadDictionary();
        }
        String msg = getMessage(dictionary,key);
        int pos = msg.indexOf('$');
        if (pos==-1){
            return msg;
        }
        else {
            return msg.substring(0,pos);
        }
    }
    public static String getLastPartOfMessage(String key){
        if (key==null || key.length()==0){
            throw new RuntimeException("GetMessage without key");
        }
        if (dictionary==null){
            loadDictionary();
        }
        String msg = getMessage(dictionary,key);
        int pos = msg.lastIndexOf('$');
        if (pos==-1){
            return msg;
        }
        else {
            return msg.substring(pos+1);
        }
    }
    public static String getParameterizedMessage(String key, String [] params){
        if (dictionary==null){
            loadDictionary();
        }
        return getParameterizedMessage(dictionary,key,params);
    }
    private static void loadDictionary(){       
        String fileName = getPropertiesPath()+dictionaryFileName;
        //String fileName = "se/prv/register/admin/dao/sql-map-config.xml";

        try {
            dictionary=new Properties();
            //InputStream fileInput =  Class.forName("se.prv.register.admin.util.MessageHandler").getClassLoader().getResourceAsStream(fileName);
            InputStream fileInput =  Class.forName(className).getClassLoader().getResourceAsStream(fileName);
            dictionary.load(fileInput);
            fileInput.close();
        }
        catch(Exception e) {
            System.err.println("Exception reading propertiesfile in init "+e);
            e.printStackTrace();
            dictionary=null;
        }
    }
    private static String getCoreMessage(String str){
        StringBuffer buff = new StringBuffer();
        boolean doCopy=true;
        for (int i=0;i<str.length();i++){
            if (str.charAt(i)=='$'){
                doCopy=!doCopy;
                continue;
            }
            if (doCopy){
                buff.append(str.charAt(i));
            }
        }
        return buff.toString();
    }
    private static String getFullMessage(String str){
        int pos = str.indexOf('$');
        if (pos==-1){
            return str;
        }
        StringBuffer buff = new StringBuffer(str);

        int originalLength = buff.length();
        for (int i=pos+1;i<buff.length();i++){
            if (buff.charAt(i)== '$'){
                String key = buff.substring(pos+1,i).trim();
                String msg = getMessage(dictionary,key);
                buff.replace(pos,i+1,msg);
                if (buff.length()!=originalLength){
                    i += (buff.length()-originalLength);
                    originalLength=buff.length();
                }
                pos = buff.indexOf("$",i+1);
                if (pos==-1){
                    break;
                }
                else {
                    i = pos+1;
                }
            }
        }
        return buff.toString();
    }
//  private static void loadDictionary(){       
//      loadDictionary(dictionary,dictionaryFileName,className);
//  }
}

package se.prv.register.admin.util;

import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Properties;

import org.apache.log4j.Logger;

import se.prv.framework.general.PRVWebSphere;
import se.prv.framework.util.Strings;

public abstract class AbstractTextHandler {

        private static final String propertiesPath="//se//prv//register//properties//";
        protected static Logger logger = Logger.getLogger(AbstractTextHandler.class);

//      static {
//          loadProperties();
//      }
        protected static String getPropertiesPath(){
            return propertiesPath;
        }
        protected static String getMessage(Properties dictionary,String key){
            if (dictionary==null){
                return "ERROR";
            }
            String msg = dictionary.getProperty(key);
            //System.out.println("KEY="+key);
            if (msg==null){
                return "?!Meddelande " +key + " saknas!?";
            }
            return msg;
        }
        protected static String getParameterizedMessage(Properties dictionary,String key,String []params){
            if (dictionary==null){
                return "ERROR";
            }
            String msg = dictionary.getProperty(key);
            if (msg==null){
                return "?!Meddelande " +key + " saknas!?";
            }
            if (params==null){
                return msg;
            }
            StringBuffer buff = new StringBuffer(msg);
            for (int i=0;i<params.length;i++){
                String placeHolder = "<<"+(i+1)+">>";
                if (buff.indexOf(placeHolder)!=-1){
                    replace(buff,placeHolder,params[i]);
                }
                else {
                    remove(buff,placeHolder);
                }
            }
            return buff.toString();
        }
        public static String getParameterizedMessageTest(String key,String []params){
            String msg = "HEJ <<1>>!HUR MÅR DU? HEJ DÅ FRÅN <<2>>";
            if (msg==null){
                return "?!Meddelande saknas!?";
            }
            if (params==null){
                return msg;
            }
            StringBuffer buff = new StringBuffer(msg);
            for (int i=0;i<params.length;i++){
                String placeHolder = "<<"+(i+1)+">>";
                if (buff.indexOf(placeHolder)!=-1){
                    replace(buff,placeHolder,params[i]);
                }
                else {
                    remove(buff,placeHolder);
                }
            }
            return buff.toString();
        }
        private static void replace(StringBuffer buff,String placeHolder,String param){
            int pos = buff.indexOf(placeHolder);
            if (pos==-1){
                return;
            }
            buff.replace(pos,pos+placeHolder.length(),param);
        }
        private static void remove(StringBuffer buff,String placeHolder){
            int pos = buff.indexOf(placeHolder);
            if (pos==-1){
                return;
            }
            buff.replace(pos,pos+placeHolder.length(),placeHolder);
        }
        protected static void loadDictionary(Properties dictionary,String fileName,String className){       
            //String fileName = "se/prv/register/admin/dao/sql-map-config.xml";

            try {
                dictionary=new Properties();
                InputStream fileInput =  Class.forName("se.prv.register.admin.util.AbstractTextHandler").getClassLoader().getResourceAsStream(fileName);
                dictionary.load(fileInput);
                fileInput.close();
            }
            catch(Exception e) {
                logger.error("Exception reading propertiesfile in init "+e);
                e.printStackTrace();
                dictionary=null;
            }
        }
    }

I’ve put my messages file messages.properties in the same directory as the log4j.properties file so I think it should get picked up. What am I doing wrong?

Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T06:14:25+00:00Added an answer on June 1, 2026 at 6:14 am

    The exception you are seeing is a null pointer exception thrown from the depth of Properties.load(). The reason is that the passed parameter (fileInput) is null. Most likely because the path specified in fileName is incorrect.

    Try prepending the path with /.

    Also, make sure the file exists. The getResourceAsStream() method will look for the file in the resources associated with the class (e.g. it has to be part of the .jar if you run your program from one).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have thousands of HTML files to process using Groovy/Java and I need to
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.