gpt4 book ai didi

java - IllegalArgumentException:绑定(bind)必须为正

转载 作者:搜寻专家 更新时间:2023-10-31 08:11:51 25 4
gpt4 key购买 nike

我收到一条错误消息,指出我的界限必须为正。这是我得到它的行:

inv.setItem(i, items.get(r.nextInt(items.size())));

据我所知,它来 self 从项目列表中请求一个随机整数的部分。这就是我定义列表的方式:

List<ItemStack> items = getAllItems(level);

getAllItems() 方法如下所示:

public List<ItemStack> getAllItems(int level) {
List<ItemStack> items = new ArrayList<ItemStack>();
for (String item : settings.getChests().getStringList("chestitems." + level)) {
ItemStack toAdd = parseItem(item);
items.add(toAdd);
}
return items;
}

我得到这个堆栈跟踪:

[19:03:53 ERROR]: Error occurred while enabling KitPvP v0.5 (Is it up to date?)
java.lang.IllegalArgumentException: bound must be positive
at java.util.Random.nextInt(Unknown Source) ~[?:1.8.0_51]
at me.iamguus.gamegetsiepunt.kitpvp.chests.ChestsUtil.randomlyFillInv(ChestsUtil.java:101) ~[?:?]
at me.iamguus.gamegetsiepunt.kitpvp.Main.onEnable(Main.java:40) ~[?:?]
at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321) ~[spigot.jar:git-Spigot-5818108-a486600]
at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:335) [spigot.jar:git-Spigot-5818108-a486600]
at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405) [spigot.jar:git-Spigot-5818108-a486600]
at org.bukkit.craftbukkit.v1_8_R3.CraftServer.loadPlugin(CraftServer.java:356) [spigot.jar:git-Spigot-5818108-a486600]
at org.bukkit.craftbukkit.v1_8_R3.CraftServer.enablePlugins(CraftServer.java:316) [spigot.jar:git-Spigot-5818108-a486600]
at org.bukkit.craftbukkit.v1_8_R3.CraftServer.reload(CraftServer.java:746) [spigot.jar:git-Spigot-5818108-a486600]
at org.bukkit.Bukkit.reload(Bukkit.java:534) [spigot.jar:git-Spigot-5818108-a486600]
at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:25) [spigot.jar:git-Spigot-5818108-a486600]
at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) [spigot.jar:git-Spigot-5818108-a486600]
at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServer.java:646) [spigot.jar:git-Spigot-5818108-a486600]
at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchServerCommand(CraftServer.java:632) [spigot.jar:git-Spigot-5818108-a486600]
at net.minecraft.server.v1_8_R3.DedicatedServer.aO(DedicatedServer.java:405) [spigot.jar:git-Spigot-5818108-a486600]
at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:369) [spigot.jar:git-Spigot-5818108-a486600]
at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:657) [spigot.jar:git-Spigot-5818108-a486600]
at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:560) [spigot.jar:git-Spigot-5818108-a486600]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_51]

最佳答案

问题是您调用 Random.nextInt() 时使用的是零,它不喜欢这样。这是因为 getAllItems() 中的 List 是空的。我会通过在执行您的逻辑之前检查列表是否包含项目来防止这种情况:

List<ItemStack> items = getAllItems(level);
if(!items.isEmpty()) {
inv.setItem(i, items.get(r.nextInt(items.size())));
}

关于java - IllegalArgumentException:绑定(bind)必须为正,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32101688/

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