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

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -