Good afternoon, I have an error on line 17 of main. I have one "Student" object and another "POO1" object. I wrote the following code:
Aluno aluno = new Aluno ();
Avaliacao poo1 = aluno.getAvaliacao();
To send the notes I wrote this: // Na main aluno.setAvaliacao (2.3, 3.1, 5.2, 1.1);
//Na classe Aluno
public void setAvaliacao(double a, double b, double c, double d) {
Avaliacao x = new Avaliacao (a, b, c, d);
avaliacao = x;
}
And the Rating constructor:
public Avaliacao(double nota1, double nota2, double exercicioAula, double trabalhofinal) {
this.nota1 = nota1;
this.nota2 = nota2;
this.exercicioAula = exercicioAula;
this.trabalhoFinal = trabalhofinal;
}
The get for the notes looks like this:
public Avaliacao getAvaliacao() {
return avaliacao;
}
And the
private Avaliacao avaliacao;
My question is why is the error appearing when I'm going to print any note on main? Here's how I did the logic to show some note sent:
System.out.println("Nota 1: " + poo1.getTrabalhoFinal()); //Aqui aparece erro
//Erro: Exception in thread "main" java.lang.NullPointerException
If in doubt, follow the class Student:
public class Aluno {
private String nome;
private String matricula;
private Avaliacao avaliacao;
public Aluno() {
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getMatricula() {
return matricula;
}
public void setMatricula(String matricula) {
this.matricula = matricula;
}
public Avaliacao getAvaliacao() {
return avaliacao;
}
public void setAvaliacao(double a, double b, double c, double d) {
Avaliacao x = new Avaliacao (a, b, c, d);
avaliacao = x;
}
}
Follow the Class App:
public class Avaliacao {
private double nota1;
private double nota2;
private double exercicioAula;
private double trabalhoFinal;
public Avaliacao(double nota1, double nota2, double exercicioAula, double trabalhofinal) {
this.nota1 = nota1;
this.nota2 = nota2;
this.exercicioAula = exercicioAula;
this.trabalhoFinal = trabalhofinal;
}
public double getNota1() {
return nota1;
}
public void setNota1(double nota1) {
this.nota1 = nota1;
}
public double getNota2() {
return nota2;
}
public void setNota2(double nota2) {
this.nota2 = nota2;
}
public double getExercicioAula() {
return exercicioAula;
}
public void setExercicioAula(double exercicioAula) {
this.exercicioAula = exercicioAula;
}
public double getTrabalhoFinal() {
return trabalhoFinal;
}
public void setTrabalhoFinal(double trabalhoFinal) {
this.trabalhoFinal = trabalhoFinal;
}
}