0

I am running a very simple test:

public class BenchmarkAuto extends UiAutomatorTestCase {
    public void testDemo() throws UiObjectNotFoundException {  
            getUiDevice().pressHome();
            getUiDevice().click(650,461);
    }

When I run it on an emulator it runs fine. When I run it on my Nexus 4 I get the following error (and my devices restarts):

java.lang.NullPointerException
    at com.android.uiautomator.core.UiDevice.getDisplayWidth(UiDevice.java:379)
    at com.android.uiautomator.core.UiDevice.click(UiDevice.java:407)
    at org.zeroxlab.zeroxbenchmark.test.BenchmarkAuto.testDemo(BenchmarkAuto.java:29)

I looked at the UIDevice source code and it looks like this is the culprit:

Display display = getAutomatorBridge().getDefaultDisplay();

The display is null and causes the NullPointerException two lines later.

Anyone have any idea how to resolve this?

4

1 回答 1

1

The problem was that I had "Pointer Location" turned on in Developer options. Turned it off and it works just fine. Hopefully someone else had the same issue and this helps them :)

于 2013-10-23T13:08:44.330 回答