Java-Gaming.org Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (798)
Games in Android Showcase (234)
games submitted by our members
Games in WIP (865)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  ArrayIndexOutOfBounds WTF?  (Read 1673 times)
0 Members and 1 Guest are viewing this topic.
Offline GNecro1
« Posted 2014-07-14 18:35:18 »

My code:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
   int worldSize = 64;
   private Tile[][] tiles = new Tile[worldSize][worldSize];

   public World() {
      for (int i = 0; i < tiles.lenght; i++) {
         for (int j = 0; i < tiles[0].lenght;j++) {
            tiles[i][j] = new Grass(i * 64, j * 64); // Exception!
         }
      }
   }


The exception:

1  
2  
3  
4  
5  
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 64
   at World.World.<init>(World.java:13)
   at Main.Game.<init>(Game.java:27)
   at Main.Main.<init>(Main.java:48)
   at Main.Main.main(Main.java:153)


Why is this happening, it's not the first time and i dont know why!? Help?

Edit: Not working with lenght!

Java freak! Cheesy
Offline KevinWorkman

« JGO Plugged Duke »


Medals: 288
Projects: 12
Exp: 12 years


HappyCoding.io - Coding Tutorials!


« Reply #1 - Posted 2014-07-14 18:37:11 »

This isn't valid code. Arrays don't have a size() function, they have a length variable.

HappyCoding.io - Coding Tutorials!
Happy Coding forum - Come say hello!
Offline BurntPizza

« JGO Bitwise Duke »


Medals: 486
Exp: 7 years



« Reply #2 - Posted 2014-07-14 18:37:46 »

If that complies I'm guessing you have a List tiles variable hiding your Tile[][], as that would be tiles.length not size()

EDIT: Half-ninja'd
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline GNecro1
« Reply #3 - Posted 2014-07-14 18:40:18 »

Yea my mistake copying it it's lenght there! Not working!

Java freak! Cheesy
Offline BurntPizza

« JGO Bitwise Duke »


Medals: 486
Exp: 7 years



« Reply #4 - Posted 2014-07-14 18:42:30 »

1  
2  
3  
4  
5  
6  
for (int i = 0; i < tiles.length; i++) {
-    for (int j = 0; i < tiles[0].length;j++) {
+    for (int j = 0; j < tiles[0].length;j++) {
        tiles[i][j] = new Grass(i * 64, j * 64);
    }
}
Offline GNecro1
« Reply #5 - Posted 2014-07-14 18:44:58 »

Ok thanks! xD

Java freak! Cheesy
Pages: [1]
  ignore  |  Print  
 
 

 
Riven (45 views)
2019-09-04 15:33:17

hadezbladez (4025 views)
2018-11-16 13:46:03

hadezbladez (1468 views)
2018-11-16 13:41:33

hadezbladez (4048 views)
2018-11-16 13:35:35

hadezbladez (780 views)
2018-11-16 13:32:03

EgonOlsen (4098 views)
2018-06-10 19:43:48

EgonOlsen (4685 views)
2018-06-10 19:43:44

EgonOlsen (2762 views)
2018-06-10 19:43:20

DesertCoockie (3657 views)
2018-05-13 18:23:11

nelsongames (3867 views)
2018-04-24 18:15:36
Java Gaming Resources
by philfrei
2019-05-14 16:15:13

Deployment and Packaging
by philfrei
2019-05-08 15:15:36

Deployment and Packaging
by philfrei
2019-05-08 15:13:34

Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!