how to fix java.lang.arrayindexoutofboundsexception: 0? -


I'm a newbie for java . Anyone can help me solve the error arrayindexoutofboundsexception .

  Public square minesweeper {public static zero main (string [] args) {int m = integer. Paracet (Argos [0]); Int n = integer Paracet (Argos [1]); Double P = Double. PRSDAB (Args [2]); // Game Grid is [1.M] [1. N] is used to handle border borders Boolean [] [] Bomb = new bullion [M + 2] [N + 2]; (Int j = 1; j & lt; = n; j ++) bomb [i] [ja] = (Math.rendum ());) (int i = 1; i  

And here is an exception:

  Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 in Minesweeper.Mine (Minesweeper. : 5)  

Two things possibly as it is called index 0 (see first case

  • The array index always starts with 0 and does not have 1

    1. . So you may need to change either Is:

      • To start with 0, your loop and I
      • I instead of A Use the array index as 1-1.

    The reason you are getting the ArrayIndexOfBound exception is that the reason that you have 2 elements in an array It will be given below:

      a [0] = 1; one [1] = 2;  

    And when you use i = 1 You are able to: I & lt; = 2 are reaching you:

      a [1] - which is correct [2] - which was not expected?  

  • Comments

    Popular posts from this blog

    java - Can't add JTree to JPanel of a JInternalFrame -

    javascript - data.match(var) not working it seems -

    javascript - How can I pause a jQuery .each() loop, while waiting for user input? -