object - Specific NullPointerException Java -


I have less questions, tell me why the first example does not work and the other works as the first code of the example: < / P>

  Tiles [] myTiles = new tile [23]; Number = 1;  

The first example:

 for  (tile tile: this.myTiles) {if (number! = This.myTiles.length) {tile = new Tile (number, getResources (). GetColor (R.color.puzzle_default)); Number ++; }}  

The second example:

 for  (tile tile: this.myTiles) {if (number! = This.myTiles.length) {this MyTiles [number -1] = new tile (number, received resource). GetColor (R.color.puzzle_default)); Number ++; }}  

If I use the code in the other method in the square below

  this.myTiles [0] .getNumber ();  

This is NullPointerException.
But with the second example it works well.

I do not really know why thanks for any feedback

first loop Creates a copy of each object and

 for  (int i = 0; i  

are the elements of an object array by default as null , they will be assigned outside the loop range The basic elements of> myTiles remain on their default null value


Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -