I get a NullPointerException when I try to invoke openFileOutput() on
the instrumentation context for an InstrumentationTestCase.  Is this
by design?  I am able to use the target context.

public class ImageUtilTest extends InstrumentationTestCase
{

 /** the instrumentation context */
  private Context ctx;
  /** context of application under test */
  private Context targetCtx;

  public void setUp() throws IOException
  {
    ctx = getInstrumentation().getContext();
    targetCtx = getInstrumentation().getTargetContext();

    // copy the example image file from the assets folder to the data
folder
    InputStream in = ctx.getAssets().open("fixture/" +
LIGHTS_BUTTON_FILENAME);
    // Trying to invoke openFileOutput() on ctx (the instrumentation
context)
    // throws a NullPointerException.  Use the target context instead.
    FileOutputStream out =
targetCtx.openFileOutput(LIGHTS_BUTTON_FILENAME,
        Context.MODE_PRIVATE);
  }
}

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to