enter image description herei’m in college and a coding newbie, the professor is teaching us java but i keep encountering this error whenever i try running her codes..
this is the second time i encounter this problem but i spent so much time trying to solve it last time i don’t even remember what i did :’) can someone help me please??
(se alguém do brasil puder responder, pode mandar q eu entendo tm 🙂
2
Answers
You should pass 3 arguments as your code expects them. Currently you’re passing none. Since you’re launching your code via VSCode IDE, try to add arguments via IDE:
Run -> Add Configuration…
It will open launch.json file. Add the line with arguments to the section where the mainClass specified:
Consider adding the proper arguments as per your code’s logic: integer, double & string.
Whole launch.json should be a valid JSON file, thus pls don’t forget about commas and quotes around the arguments even if they are not strings. It should help, good luck.
Here is a great tutorial by Java, on the exception mechanism used within the framework.
What Is an Exception? (The Java™ Tutorials > Essential Java Classes > Exceptions)
The error you’re encountering states the following.
This is caused by an Exception which was thrown by one of the statements.
The first line here, outlines the type of Exception, in this case an ArrayIndexOutOfBoundsException.
Which is followed by a message—optional, although will sometimes includes relative information.
In this case it states the following.
Firstly, you’ll need to determine how to locate the error.
The last line in the error includes the line-number of which the error occurred.
In this case it is line 11, as denoted within the parentheses, after the .java file-extension.
If you look at line 11, you’ll find the following code.
There are a few statements in this line.
Firstly, you have the NumInt assignment.
Additionally, you have the Integer#parseInt method call.
And, finally, you have the args array access.
In which your syntax is specifying a resolve to index 0.
Since the Exception that was thrown is an ArrayIndexOutOfBoundsException, we can presume that the logic propagates from this final statement, the args array access.
Thus, index 0 of the args array is inaccessible, since the length of args is 0—it contains no elements.
The args parameter is an argument which is supplied and populated by the Java Virtual Machine upon the start of your program.
Here is a tutorial on Command-Line Arguments.
Command-Line Arguments (The Java™ Tutorials > Essential Java Classes > The Platform Environment).
Since you’re using VSCode, you can refer to the following tutorial on adding Launch Configurations.
VisualStudio.com – Debugging in Visual Studio Code.
If you need more assistance on adding the values, feel free to leave a comment.