java - nullPointerException in multiarray -


i making realm plugin server, , using multiarray detect location of users portals, below code:

public static string[][][] realms;  @eventhandler public void onplayerinteract(final playerinteractevent event) throws exception {   if( event.getmaterial() == material.nether_star ) {     int x = (int) event.getclickedblock().getx();     int y = (int) event.getclickedblock().gety();     int z = (int) event.getclickedblock().getz(); **  realms[x][y][z] = event.getplayer().getname();     createportal();   } } 

i nullpointerexception @ line '**', can please explain doing wrong? have googled 'java multiarrays', , seem work same way.

you getting null pointer exception because haven't initialized array.

you can initialize array this:

string string[][][] = new string[3][3][3]; 

you need know length of arrays, because if try access or save value index doesn't exists going indexarrayoutofbounds exception


Comments

Popular posts from this blog

Issues changing the value of an element in an array in matlab -

php - MySQLi binding parameters in a prepared statement doesn't work unless inserted after "WHERE" -

vb.net - Alternative to the T-SQL AS keyword -