How to Run a Simple Java Program in Eclipse?

后端 未结 5 2249
醉话见心
醉话见心 2020-12-16 18:34

As you can probably understand from the question itself, I\'m new to Java. I was given an exercise to write a Java program which receives a character, prints it and the next

5条回答
  •  有刺的猬
    2020-12-16 19:20

    The default run configuration in Eclipse runs a Java program without any arguments, hence the ArrayIndexOutOfBoundsException. Your code is trying to get first element of the args array when there aren't any!

    You can edit the run configuration to provide the arguments to run your program with. Then it should not throw this exception.

    However, a good practice is to check the size of array before accessing it's elements, more so when the array is coming as an argument from outside of your code.

提交回复
热议问题