Exception in thread, bound must be positive at java.util.random.nextInt and at main -


as new beginner in java, having trouble text adventure game, , work on it, realized unable run it. have searched google, looked here, , found no answer how fix problem.

here's error:

exception in thread "main" java.lang.illegalargumentexception: bound must positive @ java.util.random.nextint(random.java:388) @ iproject.iproject.main(iproject.java:47) 

and here code:

package iproject;  import java.util.random; import java.util.scanner;  /**  *  * @author twinbranch*/ public class iproject {  /**  *  * @param args  */ public static void main (string[] args) {  scanner in = new scanner(system.in); random rand = new random();   string[] enemies = {  }; int maxenemyhealth = 75; int enemyattackdamage = 25;   int health = 100;  int attackdamage = 50; int numhealthpots = 3; int healthpotionhealamount = 30; int healthpotiondropchance = 33; //percentage  boolean running = true; {  game: while (running) { system.out.println();  int enemyhealth = rand.nextint(maxenemyhealth); string enemy = enemies[rand.nextint(enemies.length)]; system.out.println("\t# " + enemy + "has appeared! #\n"); 

the second error:

public int nextint(int bound) { if (bound <= 0) throw new illegalargumentexception(badbound); 

i not want post whole code this, because take approximately 400 lines.

so, initial question is, know wrong code? errors making code.

the problem enemies.length zero.


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

css - Can I use the :after pseudo-element on an input field? -