Java 如何将字符串[]转换为TouchAction命令的点
我有一个坐标字符串数组,数组中的每个字符串都被分配给一个intJava 如何将字符串[]转换为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
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();