getUiDevice().pressHome();
new UiObject(new UiSelector().description("Apps")).click();
new UiObject(new UiSelector().text("Apps")).click();
new UiScrollable(new UiSelector().scrollable(true)).setAsHorizontalList().scrollIntoView(new UiSelector().text("Settings"));
new UiObject(new UiSelector().text("Settings")).click();
new UiScrollable(new UiSelector().scrollable(true)).scrollTextIntoView("Accessibility");
new UiObject(new UiSelector().text("Accessibility")).click();
最后一行代码导致我的Nexus 4出现以下错误,我试图谷歌,但无法找到任何相关信息,那么任何人都可以帮助解释错误发生的原因吗?
10-23 13:43:16.466: E/AndroidRuntime(7995): FATAL EXCEPTION: main
10-23 13:43:16.466: E/AndroidRuntime(7995): java.lang.RuntimeException: Unable to resume activity {com.android.settings/com.android.settings.SubSettings}: java.lang.NullPointerException
10-23 13:43:16.466: E/AndroidRuntime(7995): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2790)
10-23 13:43:16.466: E/AndroidRuntime(7995): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2819)
10-23 13:43:16.466: E/AndroidRuntime(7995): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2266)
10-23 13:43:16.466: E/AndroidRuntime(7995): at android.app.ActivityThread.access$600(ActivityThread.java:141)
10-23 13:43:16.466: E/AndroidRuntime(7995): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
10-23 13:43:16.466: E/AndroidRuntime(7995): at android.os.Handler.dispatchMessage(Handler.java:99)
10-23 13:43:16.466: E/AndroidRuntime(7995): at android.os.Looper.loop(Looper.java:137)
10-23 13:43:16.466: E/AndroidRuntime(7995): at android.app.ActivityThread.main(ActivityThread.java:5103)
10-23 13:43:16.466: E/AndroidRuntime(7995): at java.lang.reflect.Method.invokeNative(Native Method)
10-23 13:43:16.466: E/AndroidRuntime(7995): at java.lang.reflect.Method.invoke(Method.java:525)
10-23 13:43:16.466: E/AndroidRuntime(7995): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
10-23 13:43:16.466: E/AndroidRuntime(7995): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
10-23 13:43:16.466: E/AndroidRuntime(7995): at dalvik.system.NativeStart.main(Native Method)
10-23 13:43:16.466: E/AndroidRuntime(7995): Caused by: java.lang.NullPointerException
10-23 13:43:16.466: E/AndroidRuntime(7995): at com.android.settings.AccessibilitySettings.loadInstalledServices(AccessibilitySettings.java:586)
10-23 13:43:16.466: E/AndroidRuntime(7995): at com.android.settings.AccessibilitySettings.onResume(AccessibilitySettings.java:196)
10-23 13:43:16.466: E/AndroidRuntime(7995): at android.app.Fragment.performResume(Fragment.java:1738)
10-23 13:43:16.466: E/AndroidRuntime(7995): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:919)
10-23 13:43:16.466: E/AndroidRuntime(7995): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1057)
10-23 13:43:16.466: E/AndroidRuntime(7995): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1039)
10-23 13:43:16.466: E/AndroidRuntime(7995): at android.app.FragmentManagerImpl.dispatchResume(FragmentManager.java:1850)
10-23 13:43:16.466: E/AndroidRuntime(7995): at android.app.Activity.performResume(Activity.java:5221)
10-23 13:43:16.466: E/AndroidRuntime(7995): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2780)
10-23 13:43:16.466: E/AndroidRuntime(7995): ... 12 more
答案 0 :(得分:1)
应该是一个简单的解决方案。当您浏览应用程序时(即加载应用程序或新页面,或任何需要加载的内容)而不是使用
new UiObject(new UiSelector().description("Apps")).click();
new UiObject(new UiSelector().text("Apps")).click();
尝试使用
new UiObject(new UiSelector().description("Apps")).clickAndWaitForWindow();
new UiObject(new UiSelector().text("Apps")).clickAndWaitForWindow();