Getting NullPointerException while reading properties file | Selenium Forum
A
Amrutha Pai Posted on 02/11/2018
Below is the code :

if(prop==null)
{
prop=new Properties();
try {
FileInputStream fs= new FileInputStream(System.getProperty("user.dir")+"//src//test//resources/projectconfig.properties");
//FileInputStream fn = new FileInputStream(System.getProperty("user.dir")+"//src//config/config.properties");
prop.load(fs);
}

catch (FileNotFoundException e) {
}

getting error at below line :

openBrowser(prop.getProperty("browser_type"));

Error log:

java.lang.NullPointerException
at com.qtpselenium.core.ddf.testcases.DummyTestB.testB(DummyTestB.java:45)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
at org.testng.TestRunner.privateRun(TestRunner.java:767)
at org.testng.TestRunner.run(TestRunner.java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1198)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1123)
at org.testng.TestNG.run(TestNG.java:1031)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)


Please suggest.




S
Shanmukh kumar ch Replied on 06/11/2018

Try with this below code


FileInputStream fs = new FileInputStream(System.getProperty("user.dir") +"\\src\\test\\resources\\projectconfig.properties");


A
Ashish Thakur Replied on 07/11/2018

DummyTestB.java:45
On this line number 45
Check this line
Some object is null there


A
Amrutha Pai Replied on 12/11/2018

got it..thanks