0

i have used Property Reader Method but getting the error - Cannot invoke "Object.toString()" because the return value of java.util.Properties.get(Object) is null java.lang.NullPointerException: Cannot invoke "Object.toString()" because the return value of "java.util.Properties.get(Object)" is null at org.automation.library.PropertyReader.elementLocatorReader(PropertyReader.java:25) at org.webservices.testcase.TC_001_Homepage.startBrowser(TC_001_Homepage.java:26) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:564) at org.testng.internal.invokers.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:139) at org.testng.internal.invokers.TestInvoker.invokeMethod(TestInvoker.java:677) at org.testng.internal.invokers.TestInvoker.invokeTestMethod(TestInvoker.java:221) at org.testng.internal.invokers.MethodRunner.runInSequence(MethodRunner.java:50) at org.testng.internal.invokers.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:969) at org.testng.internal.invokers.TestInvoker.invokeTestMethods(TestInvoker.java:194) at org.testng.internal.invokers.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:148) at org.testng.internal.invokers.TestMethodWorker.run(TestMethodWorker.java:128) at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)

public class PropertyReader {

    public static String applicationConfigReader(String key) throws IOException {
        File f = new File("./Configurations/ApplicationCOnfig.properties");
        FileReader fr = new FileReader(f);
        Properties prop = new Properties();
        prop.load(fr);
        return prop.get(key).toString();
    }
    
    public static String elementLocatorReader(String key) throws IOException {
        File f = new File("./ElementLocator/Locator.properties");
        FileReader fr = new FileReader(f);
        Properties prop = new Properties();
        prop.load(fr);
        return prop.get(key).toString();
    }
}

java.lang.NullPointerException: Cannot invoke "Object.toString()" because the return value of "java.util.Properties.get(Object)" is null

Bhagat
  • 1
  • 1
  • It isn’t clear what the question is. I guess the key passed to the method isn’t in the file, but we can’t see either the key or the contents of the file. – Tim Moore May 04 '23 at 05:35

0 Answers0