• Register
0 votes
25 views

Problem :

Currently I am learning Java. I have written code in Java but it gives me below error

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 at Minesweeper.main(Minesweeper.java:5)”.
I am unable to understand above error. How can I fix above error.
8 4 2
2,300 points

1 Answer

0 votes

Solution :

I read your question on Java. As you are beginner in java you are facing these exceptions.
I think you have done two mistakes in your java code:

First mistake is you are facing the ArrayIndexOutOfBoundsException :0 it clearly  informs that your code is  trying to reach the array value with the index value which out of array range.

Second mistake is you want to use the command line arguments but you may not be entering any arguments as the parameter. The main method supposes needs 5 parameters in order to run without any error but with zero parameters. args[0]args[1]args[2], args[3] and args[4]   means You have the array with name as args[] and now you want to reach 0th, 1st ,2nd,3rd ,4th   elements of your args[] named array. But  if you are providing zero command-line parameter then you are trying to reach the null value and so you are facing;

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 at Minesweeper.main(Minesweeper.java:5)”.
5 2 1
4,980 points

Related questions

1 vote
1 answer 16 views
16 views
Problem : I have very recently started to learn programming in Java. I am trying to execute my java code but I am facing the below error. “Exception in thread "main" java.lang.arrayindexoutofboundsexception:” I am unable to understand above error. Please find below my code: ... according to my debugger*/ myodd[j] = input[i]; j++; } return myodd; } Please help me in fixing above error.
asked Mar 30 morrisBson 3.2k points
0 votes
1 answer 92 views
92 views
Problem : I am a beginner to Java programming. While executing my program i got below error exception in thread "main" java.lang.arrayindexoutofboundsexception: 10
asked Oct 23, 2019 peterlaw 6.9k points
0 votes
1 answer 19 views
0 votes
1 answer 374 views
374 views
Problem : I am getting bellow error while compiling Arraylist exception in thread "main" java.lang.indexoutofboundsexception: index: 0, size: 0
asked Oct 19, 2019 peterlaw 6.9k points
1 vote
1 answer 38 views
38 views
Problem: I am a begginer in java programming language and I have been coding for just some days. To practice my programming I wrote this code in java: public class Main { public static void main(String[] argv){ int 2count, h-l, a/b, } } But It shows me the error message ... , . expected Syntax error on token ",", ;expected at Main.main(Main.java:3) Whats is wrong in my code can anyone help me out?
asked Apr 6 LizzyM 6.1k points