• Post Reply Bookmark Topic Watch Topic
  • New Topic

OutOfBounds Exception: 0  RSS feed

 
Christian Grossbe
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
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37489
539
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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!