Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/195.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在emulator上运行uiautomator测试用例时出现空指针错误_Android_Android Uiautomator - Fatal编程技术网

Android 在emulator上运行uiautomator测试用例时出现空指针错误

Android 在emulator上运行uiautomator测试用例时出现空指针错误,android,android-uiautomator,Android,Android Uiautomator,我成功地在emulator中运行了我的第一个uiautomator测试用例,一切正常。但是当我在同一个模拟器中第二次启动同一个测试用例时。我得到了这个错误: INSTRUMENTATION_STATUS: stack=java.lang.NullPointerException at com.android.uiautomator.core.ShellUiAutomatorBridge.getDefaultDisplay(ShellUiAutomatorBridge.java:50) at co

我成功地在emulator中运行了我的第一个uiautomator测试用例,一切正常。但是当我在同一个模拟器中第二次启动同一个测试用例时。我得到了这个错误:

INSTRUMENTATION_STATUS: stack=java.lang.NullPointerException
at com.android.uiautomator.core.ShellUiAutomatorBridge.getDefaultDisplay(ShellUiAutomatorBridge.java:50)
at com.android.uiautomator.core.UiDevice.getDisplayWidth(UiDevice.java:378)
at com.android.uiautomator.core.UiDevice.click(UiDevice.java:408)
at test.uiautomator.ApiTest.testCase(ApiTest.java:172)
at java.lang.reflect.Method.invokeNative(Native Method)
at com.android.uiautomator.testrunner.UiAutomatorTestRunner.start(UiAutomatorTestRunner.java:160)
at com.android.uiautomator.testrunner.UiAutomatorTestRunner.run(UiAutomatorTestRunner.java:96)
at com.android.commands.uiautomator.RunTestCommand.run(RunTestCommand.java:91)
at com.android.commands.uiautomator.Launcher.main(Launcher.java:83)
at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:243)
at dalvik.system.NativeStart.main(Native Method)

有人知道原因吗?我没有修改测试用例中的任何行,我只是第二次运行了它。

我检查了代码,错误发生在这里:

public Display getDefaultDisplay() {
    return  DisplayManagerGlobal.getInstance().getRealDisplay(Display.DEFAULT_DISPLAY);// Nullpointer here. 
}
这可能是因为DisplayManagerGlobal.getInstance()返回NULL

见代码:

/**
 * Gets an instance of the display manager global singleton.
 *
 * @return The display manager instance, may be null early in system startup
 * before the display manager has been fully initialized.
 */
public static DisplayManagerGlobal getInstance() {
    synchronized (DisplayManagerGlobal.class) {
        if (sInstance == null) {
            IBinder b = ServiceManager.getService(Context.DISPLAY_SERVICE);
            if (b != null) {
                sInstance = new DisplayManagerGlobal(IDisplayManager.Stub.asInterface(b));
            }
        }
        return sInstance;
    }
}

请发布错误引用的代码,这样我们就可以看到问题可能在哪里了,呵呵,谢谢你的帮助。我也检查了这里,但问题是这个函数为什么返回null?为什么使用DisplayManagerGlobal而不是UiDevice?