Config Router

  • Google Sheets
  • CCNA Online training
    • CCNA
  • CISCO Lab Guides
    • CCNA Security Lab Manual With Solutions
    • CCNP Route Lab Manual with Solutions
    • CCNP Switch Lab Manual with Solutions
  • Juniper
  • Linux
  • DevOps Tutorials
  • Python Array
You are here: Home / java.lang.ArrayIndexOutOfBoundsException: 0

java.lang.ArrayIndexOutOfBoundsException: 0

August 16, 2021 by James Palmer

Problem
This ArrayIndexOutOfBoundsException: 0 means that the index 0 is not a valid index for your array args[], which in turn means that your array is empty.
In this particular case of a main() method, it means that no argument was passed on to your program on the command line.
Possible solutions

If you’re running your program from the command line, don’t forget to pass 2 arguments in the command.
If you’re running your program in Eclipse, you should set the command line arguments in the run configuration. Go to Run > Run configurations… and then choose the Arguments tab for your run configuration and add some arguments in the program arguments area.

Note that you should handle the case where not enough arguments are given, with something like this at the beginning of your main method:
if (args.length < 2) { System.err.println("Not enough arguments received."); return; } This would fail gracefully instead of making your program crash. This code expects to get two arguments when it's run (the args array). The fact that accessing args[0] causes a java.lang.ArrayIndexOutOfBoundsException means you aren't passing any.

Related

Filed Under: Uncategorized

Recent Posts

  • How do I give user access to Jenkins?
  • What is docker volume command?
  • What is the date format in Unix?
  • What is the difference between ARG and ENV Docker?
  • What is rsync command Linux?
  • How to Add Music to Snapchat 2021 Android? | How to Search, Add, Share Songs on Snapchat Story?
  • How to Enable Snapchat Notifications for Android & iPhone? | Steps to Turn on Snapchat Bitmoji Notification
  • Easy Methods to Fix Snapchat Camera Not Working Black Screen Issue | Reasons & Troubleshooting Tips to Solve Snapchat Camera Problems
  • Detailed Procedure for How to Update Snapchat on iOS 14 for Free
  • What is Snapchat Spotlight Feature? How to Make a Spotlight on Snapchat?
  • Snapchat Hack Tutorial 2021: Can I hack a Snapchat Account without them knowing?

Copyright © 2025 · News Pro Theme on Genesis Framework · WordPress · Log in