IllegalArgumentException: Bound must be positive

前端 未结 2 1098
甜味超标
甜味超标 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: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 items = getAllItems(level);
    if(!items.isEmpty()) {
        inv.setItem(i, items.get(r.nextInt(items.size())));
    }
    

提交回复
热议问题