Me ajudem achar o erro de meu código por favor!

Olá pessoal?!!
Bom, o seguinte, estou desenvolvendo um gerador de cadastro de alunos, onde posso gerar Nome, RGA, Ano de entrada, Semestre… certo!!
ai que está, depois que consegui resolver o cadastro, estou querendo fazer a minha listagem dos alunos, geral, primeiro listar todos, depois eu iria listar separado por curso…
então, na hora que eu listo ele me aparece com um erro… como eu não conseguisse buscar o getNome, e daí, tipo, parece que ele não está achando o meu vetor… bom vou mostrar o meu código Lista_Facul, Menu_Cadastro, e Aluno_Pessoa … não vou por todas as classes aqui, se não fica muita coisa né… e o problema mesmo é nisso só…
ah!!.. estou usando JFrame … oks

[code]
/*

  • Lista_Facul.java
  • Created on 14/09/2010, 20:49:25
    */

package dentro.opcoes;

/**
*

  • @author Clau159
    */
    public class Lista_Facul extends javax.swing.JFrame {
    private Object alunos;
    private Object combobox;

    /** Creates new form Lista_Facul */
    public Lista_Facul() {
    initComponents();
    }

    /** This method is called from within the constructor to

    • initialize the form.

    • WARNING: Do NOT modify this code. The content of this method is

    • always regenerated by the Form Editor.
      */
      @SuppressWarnings(“unchecked”)
      //
      private void initComponents() {

      jButton1 = new javax.swing.JButton();
      jComboBox1 = new javax.swing.JComboBox();

      setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

      jButton1.setText(“Listar”);
      jButton1.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      jButton1ActionPerformed(evt);
      }
      });

      javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
      getContentPane().setLayout(layout);
      layout.setHorizontalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
      .addContainerGap()
      .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 109, Short.MAX_VALUE)
      .addGap(44, 44, 44)
      .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 172, javax.swing.GroupLayout.PREFERRED_SIZE)
      .addGap(65, 65, 65))
      );
      layout.setVerticalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(layout.createSequentialGroup()
      .addGap(100, 100, 100)
      .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
      .addComponent(jButton1)
      .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
      .addContainerGap(177, Short.MAX_VALUE))
      );

      pack();
      }//

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:

    //************** AQUI ESTÁ O MEU ERRO!!

     for(int i=0; i< alunos.length; i++){
         if(alunos[i]!=null){
             combobox.addItem(alunos[i].getNome());
         }
     }
    

    }

    /**

    • @param args the command line arguments
      */
      public static void main(String args[]) {
      java.awt.EventQueue.invokeLater(new Runnable() {
      public void run() {
      new Lista_Facul().setVisible(true);
      }
      });
      }

    // Variables declaration - do not modify
    private javax.swing.JButton jButton1;
    private javax.swing.JComboBox jComboBox1;
    // End of variables declaration

}

/*

  • Menu_Cadastro.java
  • Created on 10/09/2010, 22:07:05
    */

package menu.curso;

import cadastro.Aluno_Pessoa;
import dentro.curso.Curso_Facul;
import dentro.curso.Enfermagem_Facul;
import dentro.curso.Historia_Facul;
import dentro.curso.Letras_Facul;
import dentro.curso.Sistemas_Facul;
import javax.swing.JOptionPane;

/**
*

  • @author Clau159
    */
    public class Menu_Cadastro extends javax.swing.JFrame {

    Aluno_Pessoa alunos[] = new Aluno_Pessoa[200];
    /** Creates new form Menu_Cadastro */
    public Menu_Cadastro() {
    //this.alunos=alunos;
    initComponents();
    setTitle(“Cadastro de Alunos UFMS - COXIM xD”);
    setLocation(450, 250);
    setResizable(false);
    }

    /** This method is called from within the constructor to

    • initialize the form.

    • WARNING: Do NOT modify this code. The content of this method is

    • always regenerated by the Form Editor.
      */
      @SuppressWarnings(“unchecked”)
      //
      private void initComponents() {

      jLabel1 = new javax.swing.JLabel();
      jLabel2 = new javax.swing.JLabel();
      jLabel3 = new javax.swing.JLabel();
      jLabel4 = new javax.swing.JLabel();
      aluno = new javax.swing.JTextField();
      curso = new javax.swing.JComboBox();
      anomatricula = new javax.swing.JComboBox();
      semestre = new javax.swing.JComboBox();
      jSeparator1 = new javax.swing.JSeparator();
      jLabel5 = new javax.swing.JLabel();
      cadastrar = new javax.swing.JButton();
      cancelar = new javax.swing.JButton();
      limpar = new javax.swing.JButton();

      setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

      jLabel1.setBackground(new java.awt.Color(0, 0, 0));
      jLabel1.setFont(new java.awt.Font(“Tahoma”, 0, 14));
      jLabel1.setText(“Aluno:”);

      jLabel2.setBackground(new java.awt.Color(0, 0, 0));
      jLabel2.setFont(new java.awt.Font(“Tahoma”, 0, 14));
      jLabel2.setText(“Curso:”);

      jLabel3.setBackground(new java.awt.Color(0, 0, 0));
      jLabel3.setFont(new java.awt.Font(“Tahoma”, 0, 14));
      jLabel3.setText(“Ano da Matricula:”);

      jLabel4.setBackground(new java.awt.Color(0, 0, 0));
      jLabel4.setFont(new java.awt.Font(“Tahoma”, 0, 14));
      jLabel4.setText(“Semestre:”);

      aluno.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      alunoActionPerformed(evt);
      }
      });

      curso.setFont(new java.awt.Font(“Tahoma”, 1, 12));
      curso.setModel(new javax.swing.DefaultComboBoxModel(new String[] { “História”, “Enfermagem”, “Letras”, “Sistemas de Informação” }));

      anomatricula.setModel(new javax.swing.DefaultComboBoxModel(new String[] { “2000”, “2001”, “2002”, “2003”, “2004”, “2005”, “2006”, “2007”, “2008”, “2009”, “2010” }));

      semestre.setModel(new javax.swing.DefaultComboBoxModel(new String[] { “Primeiro”, “Segundo”, “Terceiro”, “Quarto”, “Quinta”, “Sexto”, “Setimo”, “Oitavo” }));
      semestre.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      semestreActionPerformed(evt);
      }
      });

      jLabel5.setBackground(new java.awt.Color(0, 0, 0));
      jLabel5.setFont(new java.awt.Font(“Tahoma”, 1, 18));
      jLabel5.setText(“Cadastro de Alunos UFMS”);

      cadastrar.setFont(new java.awt.Font(“Tahoma”, 1, 12)); // NOI18N
      cadastrar.setText(“Cadastrar”);
      cadastrar.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      cadastrarActionPerformed(evt);
      }
      });

      cancelar.setFont(new java.awt.Font(“Tahoma”, 1, 12));
      cancelar.setText(“Cancela”);
      cancelar.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      cancelarActionPerformed(evt);
      }
      });

      limpar.setFont(new java.awt.Font(“Tahoma”, 1, 12));
      limpar.setText(“Limpar”);
      limpar.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      limparActionPerformed(evt);
      }
      });

      javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
      getContentPane().setLayout(layout);
      layout.setHorizontalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
      .addContainerGap(87, Short.MAX_VALUE)
      .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 239, javax.swing.GroupLayout.PREFERRED_SIZE)
      .addGap(72, 72, 72))
      .addGroup(layout.createSequentialGroup()
      .addGap(19, 19, 19)
      .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
      .addGroup(layout.createSequentialGroup()
      .addComponent(cancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE)
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 30, Short.MAX_VALUE)
      .addComponent(limpar, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE)
      .addGap(18, 18, 18)
      .addComponent(cadastrar, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE))
      .addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 354, Short.MAX_VALUE)
      .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
      .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
      .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
      .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
      .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
      .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
      .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
      .addComponent(semestre, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
      .addComponent(anomatricula, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
      .addComponent(curso, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
      .addComponent(aluno, javax.swing.GroupLayout.DEFAULT_SIZE, 231, Short.MAX_VALUE))))
      .addContainerGap(25, Short.MAX_VALUE))
      );
      layout.setVerticalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(layout.createSequentialGroup()
      .addGap(11, 11, 11)
      .addComponent(jLabel5)
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
      .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
      .addComponent(aluno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
      .addComponent(jLabel1))
      .addGap(18, 18, 18)
      .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(layout.createSequentialGroup()
      .addComponent(jLabel2)
      .addGap(18, 18, 18)
      .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
      .addComponent(jLabel3)
      .addComponent(anomatricula, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
      .addGap(18, 18, 18)
      .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
      .addComponent(jLabel4)
      .addComponent(semestre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
      .addComponent(curso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
      .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
      .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
      .addComponent(cadastrar)
      .addComponent(cancelar)
      .addComponent(limpar))
      .addContainerGap())
      );

      pack();
      }//

    private void alunoActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:
    aluno.setText("");
    curso.setSelectedIndex(0);
    anomatricula.setSelectedIndex(0);
    semestre.setSelectedIndex(0);

    }

    private void cadastrarActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:
    Curso_Facul cad = null;
    if(curso.getSelectedItem().equals(“Enfermagem”)){
    cad = new Enfermagem_Facul();
    }else if(curso.getSelectedItem().equals(“História”)){
    cad = new Historia_Facul();
    }else if(curso.getSelectedItem().equals(“Letras”)){
    cad = new Letras_Facul();
    }else if(curso.getSelectedItem().equals(“Sistemas de Informação”)){
    cad = new Sistemas_Facul();
    }

     Aluno_Pessoa a = new Aluno_Pessoa(aluno.getText(),cad);
     // uma variavel +"" converte esta variavel para String
     a.setEntrada(Integer.parseInt(anomatricula.getSelectedItem()+""));
     //getSelectedIndex pega o indice da opçao do combobox
     // primeiro=0 segundo=1 terceiro=3
     a.setSemestre(semestre.getSelectedIndex());
    
         JOptionPane.showMessageDialog(null,"Cadastro Realizado com sucesso.");
     int ind=getPosicaoLivre();
     if(ind<0 || ind> alunos.length){
         JOptionPane.showMessageDialog(null, "Não há mais posição livre para cadastrar.", "Atenção", JOptionPane.ERROR_MESSAGE);
     }else{
         alunos[getPosicaoLivre()]=a;
         //JOptionPane.showMessageDialog(null,"A Posição livre encontrada, n° "+getPosicaoLivre());
     }
             a.setRga(a.getEntrada()+"."+cad.codigo+"."+ind+1);
     JOptionPane.showMessageDialog(null, "Nome: "+a.getNome()+"\n"+
                                         "Curso: "+a.curso.getNome()+"\n"+
                                         "Ano de Entrada: "+a.getEntrada()+"\n"+
                                         "Semestre: "+a.getSemestre()+1+"°\n"+
                                         "RGA: "+a.getEntrada()+"."+cad.codigo+"."+1
    
                                         );
    

    }

    private void cancelarActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:
    new Menu_Inicial().setVisible(true);

    }

    private void limparActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:
    aluno.setText("");
    curso.setSelectedIndex(0);
    anomatricula.setSelectedIndex(0);
    semestre.setSelectedIndex(0);

    }

    private void semestreActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:
    }

    public int getPosicaoLivre(){
    for (int i=0; i<alunos.length;i++){
    if(alunos[i]==null){
    return i;
    }
    }
    return -1;
    }
    /**

    • @param args the command line arguments
      */
      public static void main(String args[]) {
      java.awt.EventQueue.invokeLater(new Runnable() {
      public void run() {
      new Menu_Cadastro().setVisible(true);
      }
      });
      }

    // Variables declaration - do not modify
    private javax.swing.JTextField aluno;
    private javax.swing.JComboBox anomatricula;
    private javax.swing.JButton cadastrar;
    private javax.swing.JButton cancelar;
    private javax.swing.JComboBox curso;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JButton limpar;
    private javax.swing.JComboBox semestre;
    // End of variables declaration

}

package cadastro;

import dentro.curso.Curso_Facul;

/**
*

  • @author Clau159
    */
    public class Aluno_Pessoa {
    public static int length;

    private String rga;
    private String nome;
    public Curso_Facul curso;
    private int entrada;
    private int semestre;

    public Aluno_Pessoa(String nome, Curso_Facul curso){

     this.nome = nome;
     this.curso = curso;
    

    }

    /**

    • @return the rga
      */
      public String getRga() {
      return rga;
      }

    /**

    • @param rga the rga to set
      */
      public void setRga(String rga) {
      this.rga = rga;
      }

    /**

    • @return the nome
      */
      public String getNome() {
      return nome;
      }

    /**

    • @param nome the nome to set
      */
      public void setNome(String nome) {
      this.nome = nome;
      }

    /**

    • @return the curso
      */
      public Curso_Facul getCurso() {
      return curso;
      }

    /**

    • @param curso the curso to set
      */
      public void setCurso(Curso_Facul curso) {
      this.curso = curso;
      }

    /**

    • @return the entrada
      */
      public int getEntrada() {
      return entrada;
      }

    /**

    • @param entrada the entrada to set
      */
      public void setEntrada(int entrada) {
      this.entrada = entrada;
      }

    /**

    • @return the semestre
      */
      public int getSemestre() {
      return semestre;
      }

    /**

    • @param semestre the semestre to set
      */
      public void setSemestre(int semestre) {
      this.semestre = semestre;
      }

}[/code]

Muito obrigado pela atenção!!!

post o código…

Matisse NetBeans mode on. :cry:

não rodei o seu codigo, mas vou ver se posso ajudar…

torne o array “alunos[]” dentro da class " Menu_Cadastro" static…

[code]static aluno_Pessoa[] alunos = new Aluno_Pessoa[200];[/code] 

depois defina o seguinte metodo… tbm na class “Menu_Cadastro”

public Aluno_Pessoa[] getArrayAlunos(){ return alunos; }

e na class “Lista_Facul” … substituia o Object alunos, por…

private Aluno_Pessoa[] alunos = new  Menu_Cadastro().getArrayAlunos();

bom, certamente o codigo contem erros, e perdao se isso nao auxilia,
ou nao eh exatamente oq tu procura…

o teu erro provavelmente vem do fato de “alunos” nao ser um array…
entao “getNome()” pegaria o nome do object… e ainda, alunos nem esta setado… o endereço seria “null”

posta ai se ajudei, e posta tbm o erro…

Grande abraço.

eai FabioQuintana blz??

Cara… vc me ajudou demais mesmo… e percebi o meu erro principal, foi ter declarado o metodo pra retornar alunos, e nem me caiu a ficha nisso…
foi um erro besta, que passei três dias procurando…

mais… nesse meu codigo tem outro erro… mais eu já corrigi… na Class Lista_Facul, só mudei o jeito do laço… mais não foi muita coisa…

for(int i=0; i< alunos.length; i++){ if(alunos[i]!=null){ combo.addItem(alunos[i].getNome()); } }

dai as coisas quee vc me passou, eu passei por lá… e deu certo…
tenho só a agradecer por ter a atenção em cima de minha dúvida…
tenha uma ótima semana!!!

Opa, nois_159, blz sim…

vi que era coisinha boba… sempre bom poder ajudar… =)

Abraço, e sucesso com seus projetos ai.