UIautomator 测试脚本 可运行,运行不正常,不停止。代码如下

package com.example.helloworld.test;

import java.io.File;
import java.security.PublicKey;

import android.os.RemoteException;

import com.android.uiautomator.core.UiDevice;
import com.android.uiautomator.core.UiObject;
import com.android.uiautomator.core.UiSelector;
import com.android.uiautomator.testrunner.UiAutomatorTestCase;

public class TestForMcLTEContact1 extends UiAutomatorTestCase{
public void testformcltecontact1() throws RemoteException {
try {
while (UiDevice.getInstance().isScreenOn()) {
//System.out.println("灭屏状态");
// }else{
if (new UiObject(new UiSelector().description("应用")).exists()) {
UiDevice.getInstance().takeScreenshot(new File("/mnt/sdcard/1.png"));
new UiObject(new UiSelector().description("应用")).click();
if (new UiObject(new UiSelector().text("集群")).exists()) {
UiDevice.getInstance().takeScreenshot(new File("/mnt/sdcard/2.png"));
new UiObject(new UiSelector().text("集群")).click();
if (new UiObject(new UiSelector().resourceId("com.bjkyhx.McLTE:id/main_contacts")).exists()) {
UiDevice.getInstance().takeScreenshot(new File("/mnt/sdcard/4.png"));
UiDevice.getInstance().pressHome();
UiDevice.getInstance().sleep();
}
}
else {
UiDevice.getInstance().swipe(300, 300, 400, 500, 50);
UiDevice.getInstance().takeScreenshot(new File("/mnt/sdcard/3.png"));
new UiObject(new UiSelector().text("集群")).click();
if (new UiObject(new UiSelector().resourceId("com.bjkyhx.McLTE:id/main_bottom")).exists()) {
UiDevice.getInstance().takeScreenshot(new File("/mnt/sdcard/5.png"));
}
}

            }
        }
    } catch (Exception e) {
        // TODO: handle exception
        //System.out.println(e.toString());
    }
}

}
调了一上午了,求解答!
图片说明

https://testerhome.com/topics/7568

manifast.xml里是不是加了权限了,把权限去掉就可以了,我也遇到了这个问题,是这样解决的