• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

arrays: IndexOutOfBounds exception

Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

The following code is from Dan Chisholm's site

When I compiled and ran this program, the output was

nullException in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2
at A14.main(A14.java:11)

I'm not able to understand why we are getting ArrayIndexOutOfBoundsException
Can someone please explain

lowercase baba
Posts: 12893
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
a3[2] points to a2.

a2[2] points to a1.

a1 only has one element.

so, a3[2][2] points to a1, which has one element, and then you try to access it's second element.
Grow your own food... or this tiny ad:
Thread Boost feature
    Bookmark Topic Watch Topic
  • New Topic