This week's book giveaway is in the Beginning Java forum.
We're giving away four copies of Get Programming with Java (MEAP only) and have Peggy Fisher on-line!
See this thread for details.
Win a copy of Get Programming with Java (MEAP only) this week in the Beginning Java 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
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

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
Posts: 39084
714
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
 
I found a beautiful pie. And a tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!