title: Android, Robotium - Issue taking screenshot
body: <p>I'm trying to take a screenshot of my Android application using Robotium, I'm using the below function that I found <a href="http://groups.google.com/group/robotium-developers/browse_thread/thread/c5cf28ef88918d7d" rel="nofollow">here</a>.</p>
  
  <pre><code>public static String SCREEN_SHOTS_LOCATION="/sdcard/"; 
  
  public static void takeScreenShot(View view, String name) throws Exception 
  { 
      view.setDrawingCacheEnabled(true); 
      view.buildDrawingCache(); 
      Bitmap b = view.getDrawingCache(); 
      FileOutputStream fos = null; 
  
      try 
      { 
           File sddir = new File(SCREEN_SHOTS_LOCATION); 
  
           if (!sddir.exists()) 
           { 
               sddir.mkdirs(); 
           } 
           fos = new FileOutputStream(SCREEN_SHOTS_LOCATION + name + "_" + System.currentTimeMillis() + ".jpg"); 
  
           if (fos != null) 
           { 
               b.compress(Bitmap.CompressFormat.JPEG, 90, fos); 
               fos.close(); 
           } 
       } 
       catch (Exception e) 
       { 
       } 
  } 
  </code></pre>
  
  <p>I'm calling it like this from my test:</p>
  
  <pre><code>takeScreenShot(solo.getView(0), "Test");
  </code></pre>
  
  <p>When I call the function, I get a NullPointerException on that line, it looks to me as if the View is null.</p>
  
  <p>I've also tried using </p>
  
  <blockquote>
    <p>solo.getViews();</p>
  </blockquote>
  
  <p>and cycling through each view and taking a screenshot, but I get a NullPointerException for each also.</p>
  
  <pre><code>ArrayList views = solo.getViews();
  
  for(int i=0; i &lt; views.size(); i++)
  {
      takeScreenShot(solo.getView(i), "Test");
  }
  </code></pre>
  
  <p>I'm new enough to Android &amp; Android test automation using Robotium, can anybody give me some advice on debugging this, or the reason why Views seem to be null and my screen captures don't work?</p>
  
  <p>TIA.</p>
  
  <p>Update</p>
  
  <pre><code>Error in testUI:
  java.lang.NullPointerException
          at com.myapp.test.UITests.testUI(UITests.java:117)
          at java.lang.reflect.Method.invokeNative(Native Method)
          at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:204)
          at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:194)
          at android.test.ActivityInstrumentationTestCase2.runTest(ActivityInstrumentationTestCase2.java:186)
          at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)
          at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)
          at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:529)
          at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1448)
  </code></pre>