• Register
0 votes
36 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

Please log in or register to answer this question.

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

0 votes
1 answer 4 views
4 views
Thank you in advance for any help?
asked Jan 5 TeamScript 9.2k points
1 vote
1 answer 21 views
21 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, 2020 morrisBson 3.2k points
0 votes
1 answer 99 views
99 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 10 views
0 votes
1 answer 46 views
0 votes
1 answer 485 views
485 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
0 votes
1 answer 8 views
8 views
Help me by solving this problem.
asked Jan 2 TeamScript 9.2k points
0 votes
1 answer 10 views
10 views
I know the problem lies with the recursion.
asked Jan 2 TeamScript 9.2k points
0 votes
1 answer 8 views
8 views
Who can help me to solve this problem?
asked Dec 28, 2020 TeamScript 9.2k points
0 votes
1 answer 16 views
16 views
Can you please tell me the root cause?
asked Dec 26, 2020 TeamScript 9.2k points