• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

array out of bounds exception

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I keep getting this array out of bounds exception on this code im doing. I cant think why it is doing it, and I dont really want to use try and catch, as I would have to put it several times in my code:



the first error occurs biggerGrid[j][i] = grid[j-1][i-1]; and if i catch that it then tells me the if (grid[x][y] == 1) line is making an error. the original. the x and y parameters are taken from get methods which find the length of both dimensions of the original array ie finding x and y in grid[x][y]
I would be really grateful for help, as I cant seem to find any way around the problem.
[ December 05, 2008: Message edited by: Martijn Verburg ]
 
peter blay
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
After speaking to a friend I realized it was where I was trying to copy the arrays across instead of cloning them. (if you don't kno what this is try looking here: http://geekswithblogs.net/dforhan/archive/2005/12/01/61852.aspx it helped me alot) Albeit I had to completely change the biggerGrid method so it just turned it into a load of if and else ifs. This isnt ideal, so I would still be grateful to anyone who helped with this, because at the moment, part of my code looks like a donkey wrote it
 
Ranch Hand
Posts: 210
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How about using switch?
 
peter blay
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I dont see how that could be implemented here. i need to basically need to check a 3 x 3 grid for each element of the array
so
1 1 1
1 0 1
1 1 1
where 0 is the cell you are checkin against, and the 1's are the cells that need to be checked
 
No, tomorrow we rule the world! With this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic