#What does it mean when it says "Index 0 out of bounds for length 0"

10 messages · Page 1 of 1 (latest)

surreal pelican
#

I have this java assignment I have to reverse-engineer and when I go to run it for the first time i'm unsure of how to solve the first issue that pops up, Can anyone help explain how it's out of bounds at 0?

alpine hemlockBOT
#

This post has been reserved for your question.

Hey @surreal pelican! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

still rose
#

Basically you start counting at zero

#

If array is of length 1, the max index is 0, length 2 - index 1, etc.

#

if an array is empty, then it will throw an exception, because index 0 does not exist

#

basically you will want to add a check if array has more than 0 elements

#

So

if (args.length > 0) {
  StackAITester maze = new StackAITester(args[0]);
  maze.walkBoard();
}
surreal pelican
#

gotya