I am writing an Espresso test for my app, and am trying to automate clicking the shutter button after opening of a camera in my app.

I am using Espresso and UIAutomator in the Android Emulator. I managed to dump this UI in UIAutomatorViewer. [![UIAutomatorViewer](https://i.stack.imgur.com/9ieoj.png)](https://i.stack.imgur.com/9ieoj.png)

I can't figure out why I am unable to click on the shutter button using UIAutomator using this code:

```
public void clickCameraShutterButton() throws UiObjectNotFoundException
{
    UiDevice device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
    UiSelector shutterSelector = new UiSelector().resourceId("com.android.camera:id/shutter_button");
    UiObject shutterButton = device.findObject(shutterSelector);
    shutterButton.click();
}

```

The camera just sits there, and the shutter button is never clicked. This is the stack trace I'm getting in the Android Studio monitor:

```
java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.app.Activity.findViewById(int)' on a null object reference

```

Any advice would be appreciated.