-1

Here's an excerpt of my prorgam:

package something.util;
public class Reports {
    public static void logStatus(LogStatus testStatus, String testDetails) {
        test.log(testStatus, testDetails);
    }
}

package something.pages;
public class MainPage {
    public void someMethod(){
        Reports.logStatus(LogStatus.INFO, "Clicked A/B Testing link");
    }
}

When I execute the code above, I keep getting NullPointerException and I am not sure why. At least a pointer to the mistake I'm making will help.

Praveen Pandey
  • 658
  • 3
  • 16
  • 32
  • Post your exception message. It should tell you exactly where the error is coming from. From there, you need to investigate why that variable is `null`. – JeffC Oct 30 '18 at 14:59

2 Answers2

1

The test object, in the Reports class, will be null in the following line.

test.log(testStatus, testDetails);

Thats why its giving NPE.

uneq95
  • 2,158
  • 2
  • 17
  • 28
0

Dont call log method directly on test

test.log(testStatus, testDetails)

you can call like this, as this is static method,

MainPage.log(testStatus, testDetails)

or this will work too,

MainPage test = new MainPage();
test.log(testStatus, testDetails)
Ashish Kamble
  • 2,555
  • 3
  • 21
  • 29