Problemas para rodar classe com o javaw [resolvido]

6 respostas
R

Criei um programa Swing simples pelo eclipse que é:

/*

  • Created on 08/06/2005
  • TODO To change the template for this generated file go to
  • Window - Preferences - Java - Code Style - Code Templates
    */
    package teste;

import javax.swing.JFrame;

import javax.swing.JCheckBox;

import javax.swing.JLabel;

/**
  • @author usiario

  • TODO To change the template for this generated type comment go to

  • Window - Preferences - Java - Code Style - Code Templates
    */
    public class Test extends JFrame {

    private javax.swing.JPanel jContentPane = null;
    
    private JCheckBox jCheckBox = null;
    
    private JLabel jLabel = null;
    
    /**
    
    • This method initializes jCheckBox
    • @return javax.swing.JCheckBox
      /
      private JCheckBox getJCheckBox() {
      if (jCheckBox == null) {
      try {
      jCheckBox = new JCheckBox();
      jCheckBox.setBounds(54, 68, 21, 17); // Generated
      jCheckBox.setText(""); // Generated
      jCheckBox.addMouseListener(new java.awt.event.MouseAdapter() {
      public void mouseEntered(java.awt.event.MouseEvent e) {
      System.out.println(“mouseEntered()”); // TODO Auto-generated Event stub mouseEntered()
      jLabel.setText(“I’m here…”);
      }
      });
      jCheckBox.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent e) {
      System.out.println(“actionPerformed()”); // TODO Auto-generated Event stub actionPerformed()
      jLabel.setText(jCheckBox.isSelected() ? “Checked” : “Unchecked”);
      }
      });
      }
      catch (java.lang.Throwable e) {
      // TODO: Something
      }
      }
      return jCheckBox;
      }
      public static void main(String[] args) {
      Test test = new Test();
      test.setDefaultCloseOperation(EXIT_ON_CLOSE);
      test.setVisible(true);
      }
      /
      *
    • This is the default constructor
      /
      public Test() {
      super();
      initialize();
      }
      /
      *
    • This method initializes this
    • @return void
      /
      private void initialize() {
      this.setSize(300,200);
      this.setContentPane(getJContentPane());
      this.setTitle(“JFrame”);
      }
      /
      *
    • This method initializes jContentPane
    • @return javax.swing.JPanel
      */
      private javax.swing.JPanel getJContentPane() {
      if(jContentPane == null) {
      jLabel = new JLabel();
      jContentPane = new javax.swing.JPanel();
      jContentPane.setLayout(null);
      jLabel.setBounds(86, 68, 70, 17); // Generated
      jLabel.setText(""); // Generated
      jContentPane.add(getJCheckBox(), null); // Generated
      jContentPane.add(jLabel, null); // Generated
      }
      return jContentPane;
      }
      }

Quando rodo pelo eclipse funciona bem, mas quando tento rodar pelo atalho, ou pelo prompt(javaw Test, dentro do diretorio do .class), vem a mensagem: “Could not find the main class. Program will exit.”

Já segui os passos para o atalho:
Destino: C:\j2sdk1.4.2_06\bin\javaw.exe Test
Iniciar em C:\eclipse\workspace\Swing (que é o raiz da aplicação);

Alguém pode me ajudar???

Renato :frowning:

6 Respostas

keller
java -classpath . teste.Test

gui. :thumbup:

keller

dica: coloque seu codigo dentro dessas tags…

codigo

gui. :thumbup:

R

Não funcionou. Vem a mensagem
"Exception in thread main java.lang.NoClassDefFoundErro: teste/Test.

Renato :?:

keller
cd \eclipse\workspace\Swing
java -classpath . teste.Test

gui. :thumbup:

cv1

Pelo jeito, vc esta com problemas com o classpath. Caso ainda nao tenha dado uma lida, esse artigo ajuda bastante: http://guj.com.br/java.artigo.108.1.guj

R

Valeu pessoal.

Acertei no problema.
No destino do atalho coloquei: “C:\j2sdk1.4.2_06\bin\javaw.exe -classpath . teste.Test”.
No Iniciar do atalho: “C:\eclipse\workspace\Swing\bin”.

Funcionou perfeitamente.

Abraços,

Renato :smiley:

Criado 9 de junho de 2005
Ultima resposta 9 de jun. de 2005
Respostas 6
Participantes 3