Win a copy of Learning Java by Building Android Games this week in the Android forum!
  • 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 ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

OutOfBounds Exception: 0  RSS feed

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey im new to the board and to java :-) hope someone can help me.
okay heres the problem:
java.lang.ArrayIndexOutOfBoundsException: 0
heres the part of the code where the error occured(in this constructor):

private boolean[][] w;
public Life(boolean[] welt)
{
System.out.println(welt.length);
w = new boolean[welt.length][0];
for (int i=0;i < welt.length; i++)
this line --->w[i][0]=welt[i];
}
welt is 1 dimensional and has the length 10
w is a 2 dimensional boolean array
i just want to put all values from welt[] into the first line of w[][], im kinda out of ideas, please help
how can this error actually occur? out of bound 0? tsts
please help
 
author & internet detective
Marshal
Posts: 38650
675
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It should read:

This creates a 2D boolean array with welt.length rows and one column. (The column has an index of 0.)
You had created an array with zero columns. Since there aren't any columns, there is no place to old the data.
Just remember that the length/size of an array is one bigger than its highest index.
 
Christian Grossbe
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yeah that sounds logical... it should look like this right?
public Life(boolean[] welt)
{
System.out.println(welt.length);
w = new boolean[welt.length][1];
for (int i=0;i < welt.length; i++)
w[i][1]=welt[i];
}
now im getting
java.lang.ArrayIndexOutOfBoundsException: 1
i dont get it
but thx for the hlp... perhaps u have another idea? :roll:
greez
 
Christian Grossbe
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
erm okay sorry im stupid but its kinda late and i cant get a focused thought :roll:
it has to be:
public Life(boolean[] welt)
{
System.out.println(welt.length);
w = new boolean[welt.length][1];
for (int i=0;i < welt.length; i++)
w[i][0]=welt[i];
}
thx for the help m8!!
greez
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!