I'm doing a house class and a port class, and in the house class I'm declaring 3 ports and when I run NullPointerException gives, could someone give me a light
class of my port
package introducaoclasses;
public class Porta {
boolean aberta;
String cor;
int dx, dy, dz;
public void abrePorta() {
this.aberta = true;
}
public void fechaPorta() {
this.aberta = false;
}
public void pinta(String nova) {
this.cor = nova;
}
public boolean estaAberta() {
return this.aberta;
}
}
My house
package introducaoclasses;
public class Casa {
Porta porta1, porta2, porta3;
String cor;
public void pintarCasa(String Cor) {
this.cor = Cor;
}
public int quantasPortasEstaoAbertas() {
int cont = 0;
if (porta1.estaAberta()) {
cont++;
}
if (porta2.estaAberta()) {
cont++;
}
if (porta3.estaAberta()) {
cont++;
}
return cont;
}
}
My main class
package introducaoclasses;
public class IntroducaoClasses {
public static void main(String[] args) {
Casa nova = new Casa();
nova.porta3.abrePorta();
}
}