java - How to put an object into an array -


how put object array? array.

public static player [] playerarray; player[] playerarray = new player [2]; 

player

public class player {     private string wpm;     private string mistakes;     private string time;      public player (string nwpm,string nmistakes, string ntime){         wpm = nwpm;         mistakes = nmistakes;         time = ntime;     }         public string getwpm(){         return wpm;     }     public string getmistakes(){         return mistakes;     }     public string gettime(){         return time;     } } 

i kept getting error

exception in thread "main" java.lang.nullpointerexception

whenever tried use player. did wrong? there else need?

edit : adding errors happened

public void setplayer1(player p){     p1wpm.settext("8");     p1mis.settext(p.getmistakes());     p1time.settext(p.gettime()); } 

for example add player object in array can do:

player[] playerarray = new player [2];  //create new player object using defined constructor p = new player("a","b","c");  // assign p 1st index of array playerarray[0] = p; 

Comments

Popular posts from this blog

SVG stroke-linecap doesn't work for circles in Firefox? -

routes - Laravel 4 Wildcard Routing to Different Controllers -

cross browser - XSLT namespace-alias Not Working in Firefox or Chrome -