ragesh-ragav 1993 ragesh-ragav 1993 - 1 year ago 160
Java Question

java.lang.NullPointerException in appium

This is my appium java code, after starting the test its stopping in app login method and says java.lang.NullPointerException. I tried all my possible solutions, but its not at all working please help to solve this problem

public class FirstAutomate {
private WebDriver driver;


public void setup() throws Exception {

File app = new File("C:\\sdk\\platform-tools\\Myapp.apk");
DesiredCapabilities capabilities = new DesiredCapabilities();
//capabilities.setCapability("BROWSER_NAME", "Android");
capabilities.setCapability("VERSION", "5.0.2");
capabilities.setCapability("deviceName","G3 Beat");
capabilities.setCapability("appPackage", "com.skooly.app");

capabilities.setCapability("app", app.getAbsolutePath());
driver = new AndroidDriver(new URL(""), capabilities);

}catch(MalformedURLException e)


// TODO Auto-generated method stub


public void AppLogin() throws InterruptedException {
//Tapping button

Answer Source

With JUnit, each of your tests, annotated with @Test, is run independently from any other. That's why you cannot set up dome data ("driver") in one @Test and expect it to be there in another @Test.

To do initialization work before each test, use the @Before annotation, as in

@Before public void setup() throws Exception { ...

This will make setup() run and set up your driver before every actual test, i.e. AppLogin() in your case. See for instance JUnit before and test.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download