java.lang.ClassCastException:java.lang.Object[]不能强制转换为android.graphics.Point[] 公共类SendText扩展UiAutomatorTestCase{ 私有字符串jsonString=“{\“A\”:[[107729],[108728],[108728],[108727],”+ "[108,727],[108,727],[108,727],[108,727],[108,727],[108,727],[108,727],[108,727],[110,724]," + "[114,717],[125,701],[134,685],[145,663],[157,636],[169,607],[179,583],[191,558],[196,547]," + "[199,540],[201,534],[202,529],[203,528],[204,525],[204,524],[204,524],[204,524],[204,524]," + "[204,524],[204,525],[204,530],[205,538],[207,549],[209,566],[216,602],[223,629],[229,653]," + "[235,671],[238,684],[241,697],[242,703],[242,707],[243,710],[243,712],[243,713],[243,713]," + "[243,713],[243,713],[244,713],[244,713],[244,713],[244,713],[242,709],[237,703],[230,695]," + "[224,684],[220,679],[215,671],[212,665],[206,658],[202,655],[200,654],[196,651],[192,648]," + "[189,646],[184,642],[182,641],[180,639],[179,637],[177,635],[176,634],[174,633],[173,631]," + "[172,630],[171,629],[170,628],[170,628],[170,627],[169,627],[169,627],[169,627],[169,627]," + "[169,629],[169,629]]}" ; public void testSendText()引发UiObjectNotFoundException{ JSONObject jsonObj; 试一试{ jsonObj=新的JSONObject(jsonString); jsonObj.getJSONArray(“A”); }捕获(JSONException e){ //TODO自动生成的捕捉块 e、 printStackTrace(); } //字符串行=null; for(int k=0;k

java.lang.ClassCastException:java.lang.Object[]不能强制转换为android.graphics.Point[] 公共类SendText扩展UiAutomatorTestCase{ 私有字符串jsonString=“{\“A\”:[[107729],[108728],[108728],[108727],”+ "[108,727],[108,727],[108,727],[108,727],[108,727],[108,727],[108,727],[108,727],[110,724]," + "[114,717],[125,701],[134,685],[145,663],[157,636],[169,607],[179,583],[191,558],[196,547]," + "[199,540],[201,534],[202,529],[203,528],[204,525],[204,524],[204,524],[204,524],[204,524]," + "[204,524],[204,525],[204,530],[205,538],[207,549],[209,566],[216,602],[223,629],[229,653]," + "[235,671],[238,684],[241,697],[242,703],[242,707],[243,710],[243,712],[243,713],[243,713]," + "[243,713],[243,713],[244,713],[244,713],[244,713],[244,713],[242,709],[237,703],[230,695]," + "[224,684],[220,679],[215,671],[212,665],[206,658],[202,655],[200,654],[196,651],[192,648]," + "[189,646],[184,642],[182,641],[180,639],[179,637],[177,635],[176,634],[174,633],[173,631]," + "[172,630],[171,629],[170,628],[170,628],[170,627],[169,627],[169,627],[169,627],[169,627]," + "[169,629],[169,629]]}" ; public void testSendText()引发UiObjectNotFoundException{ JSONObject jsonObj; 试一试{ jsonObj=新的JSONObject(jsonString); jsonObj.getJSONArray(“A”); }捕获(JSONException e){ //TODO自动生成的捕捉块 e、 printStackTrace(); } //字符串行=null; for(int k=0;k,java,android,json,android-uiautomator,Java,Android,Json,Android Uiautomator,采集接口有两种toArray方法。第一个对象[]toArray()返回集合中的所有元素,并将它们存储在Object[]类型的数组中。第二个,T[]toArray(T[]a),如果集合元素足够大,则将其存储在方法的参数中,否则,它将通过在数组上的运行时反射来分配适当大小的数组。您的代码相当于以下代码: ` ` 要修复它,只需使用邹祖建议的toArray(T[]a)版本的toArray。使用。滑动(apoints.toArray(新点[apoint.size()]),5)@ZouZou谢谢你……这很

采集接口有两种toArray方法。第一个对象[]toArray()返回集合中的所有元素,并将它们存储在Object[]类型的数组中。第二个,T[]toArray(T[]a),如果集合元素足够大,则将其存储在方法的参数中,否则,它将通过在数组上的运行时反射来分配适当大小的数组。您的代码相当于以下代码: `

`
要修复它,只需使用邹祖建议的toArray(T[]a)版本的toArray。

使用
。滑动(apoints.toArray(新点[apoint.size()]),5)@ZouZou谢谢你……这很有效@Zouzu如果我不想用jsonString.length()而是想用jsonObj传递一个数组的实际内容…这将在数组中获取数组…我该怎么做?我不确定我是否理解您想要实现的目标。你能说得更准确些吗?或者问一个新问题,这会更好:)@ZouZou语句“getUiDevice().swipe((Point[])apoints.toArray(),5);”只获取字符串的总长度,但我希望传递每个坐标,以便所有坐标都通过swipe方法
public class SendText extends UiAutomatorTestCase {

    private String jsonString = "{\"A\": [[107,729],[108,728],[108,728],[108,727]," +
        "[108,727],[108,727],[108,727],[108,727],[108,727],[108,727],[108,727],[108,727],[110,724]," +
        "[114,717],[125,701],[134,685],[145,663],[157,636],[169,607],[179,583],[191,558],[196,547]," +
        "[199,540],[201,534],[202,529],[203,528],[204,525],[204,524],[204,524],[204,524],[204,524]," +
        "[204,524],[204,525],[204,530],[205,538],[207,549],[209,566],[216,602],[223,629],[229,653]," +
        "[235,671],[238,684],[241,697],[242,703],[242,707],[243,710],[243,712],[243,713],[243,713]," +
        "[243,713],[243,713],[244,713],[244,713],[244,713],[244,713],[242,709],[237,703],[230,695]," +
        "[224,684],[220,679],[215,671],[212,665],[206,658],[202,655],[200,654],[196,651],[192,648]," +
        "[189,646],[184,642],[182,641],[180,639],[179,637],[177,635],[176,634],[174,633],[173,631]," +
        "[172,630],[171,629],[170,628],[170,628],[170,627],[169,627],[169,627],[169,627],[169,627]," +
        "[169,629],[169,629]]}" ;

    public void testSendText() throws UiObjectNotFoundException {   

        JSONObject jsonObj;
        try {
            jsonObj = new JSONObject(jsonString);
            jsonObj.getJSONArray("A");
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        //String line = null;

        for(int k = 0; k < jsonString.length(); k++ ){
            Vector<Point> apoints = new Vector<Point>();
            apoints.add(new Point());
            getUiDevice().swipe((Point[])apoints.toArray(), 5);
        }
    }
}
Object[] x = new Object[1];

x[0] = "Test";
System.out.println(((String[]) x)[0]); //Throws a ClassCastException