title: Appium driver null pointer exception
body: <p>I am new to Appium and just getting started, I have been following an example and using a basic Contacts apk on Android tablet to start against. The code I have is pretty much copied from the example I am following but when I try to run the test I get a null pointer exception. I did some debugging and find that the driver = null is why I am getting this exception. I looked around and found some code that I thought might help but it hasn't.</p>
  
  <p>The code I have is </p>
  
  <pre><code>import io.appium.java_client.AppiumDriver;
  import io.appium.java_client.android.AndroidDriver;
  import io.appium.java_client.remote.MobileCapabilityType;
  import org.junit.After;
  import org.junit.Before;
  import org.openqa.selenium.WebElement;
  import org.openqa.selenium.remote.DesiredCapabilities;
  import org.testng.annotations.Test;
  import java.util.concurrent.TimeUnit;
  import java.net.MalformedURLException;
  import java.net.URL;
  
  public class addContact {
  
      AppiumDriver driver;
  
      @Before
      public void setUp () throws Exception {
  
          new DesiredCapabilities();
          DesiredCapabilities capabilities = DesiredCapabilities.android();
             capabilities.setCapability(MobileCapabilityType.DEVICE_NAME,"AndroidTestDevice");
  
          try
          {
              driver = new AndroidDriver(new URL("http://0.0.0.0:4723/wd/hub"), capabilities);
              driver.manage().timeouts().pageLoadTimeout(120, TimeUnit.SECONDS);
  
          }
          catch (MalformedURLException e)
          {
              System.out.println("URL init error");
          }
  
      }
  
      @After
      public void tearDown () throws Exception {
          driver.quit();
      }
  
      @Test
      public void addNewContact (){
  
  
       System.out.println (driver);
       WebElement addContactButton = driver.findElementById("com.example.android.contactmanager:id/addContactButton");
       addContactButton.click();
      }
  
  }`
  </code></pre>
  
  <p>The exception I get is :</p>
  
  <blockquote>
  <pre><code>java.lang.NullPointerException
  at addContact.addNewContact(addContact.java:49)
  </code></pre>
  </blockquote>
  
  <p>and the line this occurs in is :</p>
  
  <pre><code>WebElement addContactButton = driver.findElementById("com.example.android.contactmanager:id/addContactButton");
  </code></pre>