gpt4 book ai didi

java - 使用 charAt 时出现字符串 outOfBoundsException

转载 作者:行者123 更新时间:2023-12-01 21:55:16 25 4
gpt4 key购买 nike

我有以下代码:

@SuppressWarnings("resource")
public void changeSkin(String name){
try {
URL uuidURL = new URL("https://api.mojang.com/users/profiles/minecraft/" + name);

String uuid = new Scanner(uuidURL.openStream(), "UTF-8").useDelimiter("\\A").next();
uuid = uuid.substring(7, 39);

System.out.println(uuid); // works

URL valueURL = new URL("https://sessionserver.mojang.com/session/minecraft/profile/" + uuid + "?unsigned=false");

String value = new Scanner(valueURL.openStream(), "UTF-8").useDelimiter("\\A").next();
value = value.replace('"', '!');
value = value.replaceAll("!value!:!", "*");
value = value.replaceAll("=!,", "+");
value = value.substring(value.charAt('*'), value.charAt('+')); // Gives an error outOfBounds: -13

String signature = new Scanner(valueURL.openStream(), "UTF-8").useDelimiter("\\A").next();
signature = signature.replaceAll("!signature!:!", "_");
signature = signature.replaceAll("=!}]}", "~");
signature = signature.substring(value.charAt('_'), value.charAt('~'));

System.out.println(signature);
System.out.println(value);

//profile.getProperties().put("textures", new Property(value, signature));

} catch (Exception e) {
e.printStackTrace();
}

}

运行时会抛出 outOfBoundsException: -13

但是怎么会抛出负数呢?

感谢您的帮助

编辑:这是网站:https://sessionserver.mojang.com/session/minecraft/profile/e96ca9800c6c4a1588a2922a02ae1080?unsigned=false

最佳答案

我猜你正在制作某种《我的世界》机器人之类的东西......但这无关紧要。

您错误地使用了 charAt。

https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#charAt(int)

您要查找的是indexOf

https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#indexOf(int)

关于java - 使用 charAt 时出现字符串 outOfBoundsException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34486463/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com