-1

enter image description here

I am using Java 8 update 251

The error that shows up:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0 at first_project.main(first_project.java:6)

AurumTechie
  • 143
  • 2
  • 11
  • it appears you are new to java, right ? Do you know any other programming language already ? – ashish singh May 22 '20 at 04:28
  • Does this answer your question? [What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it?](https://stackoverflow.com/questions/5554734/what-causes-a-java-lang-arrayindexoutofboundsexception-and-how-do-i-prevent-it) – Björn Zurmaar May 22 '20 at 08:07

2 Answers2

2

The error is displayed as you are not passing any parameter while running the program. Try running the program from command line and passing argument. Eg:

c:\> java MyFirstJavaProgram arg0_value

or you can provide argument in Run Configuration of eclipse as well.

Aniket Sahrawat
  • 11,710
  • 3
  • 36
  • 63
Vivek Goel
  • 705
  • 2
  • 10
  • 20
  • 1
    The official term would be "command-line arguments" or "program arguments". Googling "Eclipse ..." (Using either term) would provide the information needed to understand this. Either way, +1, although I recommend giving the OP info for expanding on this topic. – Dioxin May 22 '20 at 04:39
1

This program is expecting a command line argument; if you run this with Eclipse it will cause this issue. You need run this program from the shell with the proper arguments.

Compile file:

javac java_filepathofFile argument 

Use java to run:

java class_filepathofFile argument 
Paul Roub
  • 35,848
  • 27
  • 79
  • 88
Sachin Kumar
  • 934
  • 6
  • 13