The instrumentation code is running as part of the application's process, not in its own process, so it is running under the app's uid and not its own.
On Wed, Apr 27, 2011 at 3:10 PM, Andrew Ball <[email protected]> wrote: > 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 > -- Dianne Hackborn Android framework engineer [email protected] Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails. All such questions should be posted on public forums, where I and others can see and answer them. -- 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

