0

I was trying to make a minesweeper program for homework, but I got a problem with making and positioning mines that hasn't solved for 3 hours. My code is

for(int i = 0; i < bomb; i++)
{
    int x = randomGenerator.nextInt(m);
    int y = randomGenerator.nextInt(n);
    mines[x][y] = Integer.parseInt("*");
    i++;
    if(i == bomb)
    break;
}

Can anyone knows what is wrong with it?

Hovercraft Full Of Eels
  • 276,051
  • 23
  • 238
  • 346
  • 2
    in addition to being a duplicate, `Integer.parseInt("*")` is illegal code. Welcome to Stackoverflow, but please make sure to read [how do I ask a good question](/help/how-to-ask) thoroughly at least once (typically the best time for that is before you post your first ever question) and understand that code needs to at least compile for it to be good question code. – Mike 'Pomax' Kamermans Mar 09 '17 at 17:36
  • You have not shown enough of the code to deduce what causes the exception. If your question is "What is an ArrayIndexOutOfBoundsException?" then see the linked duplicate question. If you just can't figure out what causes it in your situation, neither can we with what I see. You have not even given us a stack trace of even the line in error either, though I assume it's `mines[x][y] = ...`. What is `m`? What is `n`? How large is `mines[][]`? If you can answer these questions, you might be able to answer your own question on your own; if not, edit your question. – Loduwijk Mar 09 '17 at 17:38
  • @Mike'Pomax'Kamermans Maybe a nitpick, as it might not be what you meant, but `Integer.parseInt("*");` is not *illegal code*. It will not have the expected result OP wants, sure, but the code itself is legal. – Loduwijk Mar 09 '17 at 17:40
  • Fair enough: `Integer.parseInt("*")` will compile, but is a *guaranteed* `java.lang.NumberFormatException` runtime error that doesn't just need a try/catch, but literally shouldn't be there. If you want to throw an error, throw an error. Don't use an API call that you know throws an error. – Mike 'Pomax' Kamermans Mar 09 '17 at 17:52

0 Answers0