I have a 'PropertiesUtil' class for reading properties from a configuration file. The code of the class is given below:
public class PropertiesUtil {
public static Properties prop;
public static String databaseConnectivityString;
public static String databaseUserName;
public static String databaseUserPassword;
static {
try {
prop.load(new FileReader(new File("config.prop")));
databaseConnectivityString = prop.getProperty("databaseConnectivityString");
databaseUserName = prop.getProperty("databaseUserName");
databaseUserPassword = prop.getProperty("databaseUserPassword");
} catch (IOException | NumberFormatException ex) {
LoggerUtil.getLogger().severe("Problem loading or Reading Configuration file");
}
}
}
when I call the following code from another class 'Test' with a main method I get a NullPointerException. The code of the 'Test' Class is given below. Kindly help me troubleshoot.
public class Test {
public static void main(String... args) throws IOException {
System.out.println(PropertiesUtil.databaseUserName);
}
}