14
I’m developing a project in Java and he’s in error, I’ve found it but I don’t understand it.
public class Time{
private String nome;
private ArrayList<Jogador> jogadores;
private Integer gols;
public void addGol(){
this.gols = this.gols+1;
}
}
public class App {
public static void main (String args[]){
Time time = new Time("A");
time.addGol();
}
}
He is generating Exception in thread "main" java.lang.NullPointerException
,
The reason is the private Integer gols;
that’s like Integer
, if I put int
works normally.
- Does anyone know why?
- Aren’t the two the same thing? being
int
primitive andInteger
object?
Thanks, solved, did not know this fact.
– Guilherme Lautert