IllegalArgumentException: Bound must be positive

前端 未结 2 1094
甜味超标
甜味超标 2020-12-04 01:40

I get an error saying that my bound must be positive. Here is the line I get it on:

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

As

相关标签:
2条回答
  • 2020-12-04 02:09

    As far as your stacktrace says,

    java.lang.IllegalArgumentException: bound must be positive at java.util.Random.nextInt(Unknown Source) ~[?:1.8.0_51]

    The argument to nextInt needs to be a positive integer. You will need to find out where you're passing a non-positive input to that method.

    0 讨论(0)
  • 2020-12-04 02:16

    The issue is that you are calling Random.nextInt() with a zero and it doesn't like that. That is happening because the List from getAllItems() is empty. I would prevent this situation by checking that the list has items before performing your logic:

    List<ItemStack> items = getAllItems(level);
    if(!items.isEmpty()) {
        inv.setItem(i, items.get(r.nextInt(items.size())));
    }
    
    0 讨论(0)
提交回复
热议问题