How do I put an object into my array? This is my 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 this error
Exception in thread "main" java.lang.NullPointerException
whenever I tried to use player. Did I do something wrong? Is there anything else you need?
Edit : adding where the errors happened
public void setPlayer1(Player p){
p1WPM.setText("8");
p1Mis.setText(p.getMistakes());
p1Time.setText(p.getTime());
}
NullPointerExceptionoccur? You are declaringplayerArraytwicemain()method code.Also, why are you declaringplayerArraytwice?setPlayer1()? Add proper code not just snippets which can't be glued togetherp1WPM,p1Mis,p1Time