Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/325.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
Java 如何将字符串[]转换为TouchAction命令的点_Java_Arrays_String_Appium_Coordinates - Fatal编程技术网

Java 如何将字符串[]转换为TouchAction命令的点

Java 如何将字符串[]转换为TouchAction命令的点,java,arrays,string,appium,coordinates,Java,Arrays,String,Appium,Coordinates,我有一个坐标字符串数组,数组中的每个字符串都被分配给一个int String[] A = {"217, 423", "557, 408", "927, 393"}; Random B=new Random(); int randomCoord=B.nextInt(3); 我希望能够像这样将这些坐标插入下面的命令中 TouchAction touchAction = new TouchAction(driver); touchAction.tap(PointOption.point(A[rand

我有一个坐标字符串数组,数组中的每个字符串都被分配给一个int

String[] A = {"217, 423", "557, 408", "927, 393"};
Random B=new Random();
int randomCoord=B.nextInt(3);
我希望能够像这样将这些坐标插入下面的命令中

TouchAction touchAction = new TouchAction(driver);
touchAction.tap(PointOption.point(A[randomCoord])).perform();
但是当我这样做的时候,我得到一个错误,上面写着

类型点选项中的方法点(点)不适用于参数(字符串)

所以我试着把字符串转换成这样的int

TouchAction touchAction = new TouchAction(driver);
touchAction.tap(PointOption.point(Integer.parseInt(A[randomCoord]))).perform();
但我犯了这个错误

type point选项中的方法点(int,int)不适用于参数(int)


有人能帮我吗?我希望每次运行代码时,代码都能从字符串数组中插入一组随机坐标。

不知道如何才能获得NumberFormatException。。但是您需要将A的随机索引解析为单独的整数

    String[] points = A[randomCoord].split(",");
    int x = Integer.parseInt(points[0].trim());
    int y = Integer.parseInt(points[1].trim());
    TouchAction touchAction = new TouchAction(driver);
    touchAction.tap(PointOption.point(x, y)).perform();

不知道你怎么会没有数字格式异常。。但是您需要将A的随机索引解析为单独的整数

    String[] points = A[randomCoord].split(",");
    int x = Integer.parseInt(points[0].trim());
    int y = Integer.parseInt(points[1].trim());
    TouchAction touchAction = new TouchAction(driver);
    touchAction.tap(PointOption.point(x, y)).perform();