I am developing a project in Java and it is in error, I have already found it but I do not 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();
}
}
It is generating Exception in thread "main" java.lang.NullPointerException
,
The reason is private Integer gols;
that is as Integer
, if I put int
it works normally.
- Does anyone know why?
- Are not two the same? being
int
primitive andInteger
object?