'NullPointer Exception with @BeforeClass but not with @BeforeMethod using Selenium with Java and TestNG

I'm changing test and it turns out that it will be better to split it into three separate tests.

I've created setup method that should be run before whole class.

When I'm using @BeforeMethod with one huge test everything is ok, but when I change this into 3 tests and @BeforeClass I'm getting this

java.lang.NullPointerException
   at com.framework.ui.driver.lifecycle.SingleUseDriverLifecycle.getWebDriver(SingleUseDriverLifecycle.java:36)
   at com.framework.ui.UITestLifecycle.getWebDriver(UITestLifecycle.java:149)
   at com.framework.ui.pages.BasePage.<init>(BasePage.java:32)
   at adminPanel.pages.LoginAP.<init>(LoginAP.java:19)

Browser starts for a second and it's closed very fast.

enter image description here

Any ideas what can be wrong?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source