Solucionado (ver solução)
Solucionado
(ver solução)
2
respostas

Cannot find symbol - Aula 4 - Array

Costumo assistir aos vídeos ao mesmo tempo que vou escrevendo o código junto com o professor. No vídeo da aula 4 sobre array eu não consegui compilar meu código. Aparecem 9 erros de "cannot find symbol" Se alguém puder me ajudar :D Ahhhhh, sou mega iniciante na área de programação, então se puder explicar como para uma criança de 10 anos, facilita pra mim, haha

class Turma {
    Aluno [] notas;

    void imprimeNotas() {
        for(int i = 0; i < this.alunos.length; i++) {
            Aluno aluno = this.alunos [i];
            if (aluno == null) continue;
            System.out.println(aluno.nota);
        }
    }
}


class Aluno {
    String nome;
    int nota;
}


class TesteDaTurma {
    public static void main (String [] args){

        Turma fj11 = new Turma();
        fj11.alunos = new Aluno[10];

        fj11.alunos[0] = new Aluno();
        fj11.alunos[0].nome = "Mauricio";
        fj11.alunos[0].nota = 9;

        fj11.alunos[1] = new Aluno();
        fj11.alunos[1].nome = "Marcelo";
        fj11.alunos[1].nota = 5;

        fj11.imprimeNotas();
    }
}

Abaixo o erro ao compilar:

 javac Aula4.java
Aula4.java:5: error: cannot find symbol
                for(int i = 0; i < this.alunos.length; i++) {
                                       ^
  symbol: variable alunos
Aula4.java:6: error: cannot find symbol
                        Aluno aluno = this.alunos [i];
                                          ^
  symbol: variable alunos
Aula4.java:24: error: cannot find symbol
                fj11.alunos = new Aluno[10];
                    ^
  symbol:   variable alunos
  location: variable fj11 of type Turma
Aula4.java:26: error: cannot find symbol
                fj11.alunos[0] = new Aluno();
                    ^
  symbol:   variable alunos
  location: variable fj11 of type Turma
Aula4.java:27: error: cannot find symbol
                fj11.alunos[0].nome = "Mauricio";
                    ^
  symbol:   variable alunos
  location: variable fj11 of type Turma
Aula4.java:28: error: cannot find symbol
                fj11.alunos[0].nota = 9;
                    ^
  symbol:   variable alunos
  location: variable fj11 of type Turma
Aula4.java:30: error: cannot find symbol
                fj11.alunos[1] = new Aluno();
                    ^
  symbol:   variable alunos
  location: variable fj11 of type Turma
Aula4.java:31: error: cannot find symbol
                fj11.alunos[1].nome = "Marcelo";
                    ^
  symbol:   variable alunos
  location: variable fj11 of type Turma
Aula4.java:32: error: cannot find symbol
                fj11.alunos[1].nota = 5;
                    ^
  symbol:   variable alunos
  location: variable fj11 of type Turma
9 errors
2 respostas
solução!

O nome do seu array na classe Turma é notas, porém você está usando o termo alunos que não existe. Tente mudar de alunos para notas.

Funcionou :D Muito obrigado!

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software