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

sql - VB.NET Operand type clash: date is incompatible with int error -

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

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -