Erro na aplicação rodando em windows (Linux roda sem problemas)?

6 respostas
brunorota

Ae galera
Eu fiz uma aplicação, fiz tudo ela em ambiente linux
Ae hj eu fui testar ela no windows
Compilei ela, roda normal, soh que quando eu clico no JButton pra adicionar, remover ow alterar um item
Da o seguinte erro

Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: classes/help/PersistenciaGUI at ClassesGUI.ItemGUI.mouseClicked(ItemGUI.java:226) at java.awt.AWTEventMulticaster.mouseClicked(Unknown Source) at java.awt.Component.processMouseEvent(Unknown Source) at javax.swing.JComponent.processMouseEvent(Unknown Source) at java.awt.Component.processEvent(Unknown Source) at java.awt.Container.processEvent(Unknown Source) at java.awt.Component.dispatchEventImpl(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Window.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.EventQueue.dispatchEvent(Unknown Source) at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.run(Unknown Source)

Detalhe no linux roda normal, nao da erro nenhum, deu erro agora no windows

Se alguem puder me ajudar

Atenciosamente

6 Respostas

thiago.correa

Pelo visto ele não está achando a tua classe: NoClassDefFoundError: classes/help/PersistenciaGUI

brunorota

qual seria o problema?

Eu importei os pacotes tudo certinho =/

Eu tinha pensado q era isso, mais eu fui v, eu importei os pacotes tudo certinho =/

brunorota
código
package ClassesGUI;
import java.awt.Dimension;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.text.ParseException;
import java.util.Vector;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFormattedTextField;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.UIManager;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableColumnModel;
import help.PersistenciaGUI;


import Classes.Componente;
import ClassesDB.ComponenteDB;
import ClassesDB.DescricaoDB;


public class ComponenteGUI extends JFrame implements MouseListener{
	
	private JPanel container = null;
	private JLabel lNome = null;
	private JTextField txtNome = null;
	private JButton btnAdd = null;
	private JButton btnUpdate = null;
	private JButton btnDelete = null;
	private JTable table = null;
	private JScrollPane jScrollPane = null;
	private int cod;
	
	private ComponenteDB cdb;
	private Componente c;
	
	ComponenteGUI(){
		super();
		initialize();
	}
	
	public void initialize(){
		
		this.setSize(335, 400);
		this.setLocationRelativeTo(null);
		this.setResizable(false);
		this.setContentPane(getContainer());
	}
	
	public JPanel getContainer(){
		
		if(container == null){
			
			container = new JPanel();
			container.setLayout(null);
				
			lNome = new JLabel();
			lNome.setBounds(20, 30, 40, 20);
			lNome.setText("Nome");
			container.add(lNome);
			
			txtNome = new JTextField();
			txtNome.setBounds(80, 30, 230, 20);
			container.add(txtNome);
			
			btnAdd = new JButton();
			btnAdd.setBounds(10, 330, 90, 30);
			btnAdd.setText("Add");
			btnAdd.addMouseListener(this);
			container.add(btnAdd);
			
			btnUpdate = new JButton();
			btnUpdate.setBounds(110, 330, 90, 30);
			btnUpdate.setText("Alterar");
			btnUpdate.addMouseListener(this);
			container.add(btnUpdate);
			
			btnDelete = new JButton();
			btnDelete.setBounds(210, 330, 90, 30);
			btnDelete.setText("Delete");
			btnDelete.addMouseListener(this);
			container.add(btnDelete);
			
			container.add(getJScrollPane());
		}
		
		return container;
	}
	
	public static void main(String[] args){
		
		try {
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		} catch(Exception e){
			e.printStackTrace();
		}
		ComponenteGUI c = new ComponenteGUI();
		c.setTitle("CADASTRO DE COMPONENTES");
		c.setVisible(true);
		c.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
	}

	public JTable getTable(){
		
		Vector cabecalho = new Vector();
		cdb = new ComponenteDB();
		
		cabecalho.add("Codigo");
		cabecalho.add("Nome");
		
		table = new JTable(cdb.dadosComponentes(), cabecalho);
		this.defineRenderers();
		table.addMouseListener(this);
		table.setDoubleBuffered(false);
		
		return table;
	}
	 
	public JScrollPane getJScrollPane(){
		
		if(jScrollPane == null){
			
			jScrollPane = new JScrollPane();
			jScrollPane.setBounds(10, 70, 300, 230);
			jScrollPane.setViewportView(getTable());
			jScrollPane.addMouseListener(this);
		}
		return jScrollPane;
	}

	public void mouseClicked(MouseEvent e) {
		
		//Evento - Adiciona um componente 
		if(e.getSource() == this.btnAdd && new PersistenciaGUI().getTextSelected(txtNome) == false){
			
			c = new Componente();
			
			c.setNomeComponente(txtNome.getText().toUpperCase());
			
			if(txtNome.getText().length() <= 39){
				
				new ComponenteDB().addComponente(c);
				
				jScrollPane.setViewportView(getTable());
				clear();
			}
			else
			{
				new PersistenciaGUI().avisoString();
				txtNome.setText("");
			}
		
		}
		
		//Evento - Altera Dados
		if(e.getSource() == this.btnUpdate && new PersistenciaGUI().getTextSelected(txtNome) == false){
			
			
			if(txtNome.getText().length() <= 39){
				
				new ComponenteDB().updateComponente(getCod(), txtNome.getText().toUpperCase());
				
				jScrollPane.setViewportView(getTable());
			}
			else
			{
				new PersistenciaGUI().avisoString();
				txtNome.setText("");
			}
		}
		
		//Evento  - Deleta os Dados
		if(e.getSource() == this.btnDelete && new PersistenciaGUI().getTextSelected(txtNome) == false){
			
			String[] botoes = {"Sim", "Não"};
			String text = "Deseja excluir a estrutura/equipamento?";
			String title = "Aviso";
			
			if(new PersistenciaGUI().getJDialog(botoes, title, text) == 0){
				
				new ComponenteDB().deleteComponente(getCod());
				
				new DescricaoDB().deleteComponenteDescricao(getCod());
				
				jScrollPane.setViewportView(getTable());
				clear();
			}
		}
		
		//Evento para preencher o JTextField com os campos da tabela
		if(e.getSource() == this.table){
			
			setCod(Integer.parseInt((String) table.getValueAt(table.getSelectedRow(), 0)));
			txtNome.setText((String) table.getValueAt(table.getSelectedRow(), 1));
		}
		
	}

	public void mouseEntered(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	public void mouseExited(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	public void mousePressed(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	public void mouseReleased(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}
	
	public void clear(){

		txtNome.setText("");	
	}
	
	private void defineRenderers() {  
		 
	     DefaultTableCellRenderer rendererCentro = new DefaultTableCellRenderer();  
	     rendererCentro.setHorizontalAlignment(SwingConstants.CENTER);  
	     DefaultTableCellRenderer rendererDireita = new DefaultTableCellRenderer();  
	     rendererDireita.setHorizontalAlignment(SwingConstants.RIGHT);  
	     DefaultTableCellRenderer rendererEsquerda = new DefaultTableCellRenderer();  
	     rendererEsquerda.setHorizontalAlignment(SwingConstants.LEFT);  
	   
	     JTableHeader header = table.getTableHeader();  
	     header.setPreferredSize(new Dimension(0, 25));   
	     
	     TableColumnModel modeloDaColuna = table.getColumnModel();  
	       
	     modeloDaColuna.getColumn(0).setCellRenderer(rendererEsquerda);  
	     modeloDaColuna.getColumn(1).setCellRenderer(rendererEsquerda);   
	   
	     modeloDaColuna.getColumn(0).setMaxWidth(60);  
	     modeloDaColuna.getColumn(1).setMaxWidth(250);  
	} 
	
	public void setCod(int cod){
		this.cod = cod;
	}
	
	public int getCod(){
		return cod;
	}

}

Codigo da classe persistencia

package help;

import javax.swing.JOptionPane;
import javax.swing.JTextField;

	public class PersistenciaGUI {
	
	public int getJDialog(String[] botoes, String title, String text){
		
		int i = JOptionPane.showOptionDialog(  
			     null,  
			     text, // a mensagem  
			     title, // o título da janela  
			     JOptionPane.DEFAULT_OPTION, // indica que o usuário fornecerá as opções  
			     JOptionPane.WARNING_MESSAGE, // exibirá o ícone de confirmação  
			     null,  
			     botoes, // um array contendo os títulos dos botões a serem exibidos  
			     botoes[0] // o botão selecionado por padrão  
				); 
		
		return i;
	}
	
	public void avisoCodigo(){
		
		JOptionPane.showMessageDialog(null,
		"Código inválido ou já existente. Favor digitar outro código", "ERRO", JOptionPane.ERROR_MESSAGE);
	}
	
	public void avisoString(){
		
		JOptionPane.showMessageDialog(null,
		"Nome muito grande. Favor digitar um nome de no máximo 40 caracteres.", "ERRO", JOptionPane.ERROR_MESSAGE);
	}

	public boolean getTextSelected(JTextField t){
		
		boolean selected = t.getText().trim().equals("");
		
		return selected;
	}
	
	public int getTamanhoString(String t){
	
		return t.length();
	}
	
	public boolean isDataValida(String d){
		
		int dia = 0, mes = 0, ano = 0;
		String[] data = d.split("-");
		boolean dataValido = false;
		
		dia = Integer.parseInt(data[0]);
		mes = Integer.parseInt(data[1]);
		ano = Integer.parseInt(data[2]);
		
		if(dia <= 0)
			dataValido = false;
		else
		if(ano < 1 || ano >= 3000)
			dataValido = false;
		else
		if(mes == 1 || mes == 3 || mes == 5 || mes == 7 || mes == 8 || mes == 10 || mes == 12){
			if(dia <= 31)
				dataValido = true;
		}
		else
		if(mes == 4 || mes == 6 || mes == 9 || mes == 11){
			if(dia <= 30)
				dataValido = true;
		}
		else
		if(mes == 2 && (ano % 4 == 0) && (ano % 100 != 0) || (ano % 400 == 0)){
			if(dia <= 29)
				dataValido = true;
		}
		else
		if(mes == 2){
			if(dia <= 28)
				dataValido = true;
		}
		
		return dataValido;
	}

}

Nao sei oq esta dando errado =/

leonardom

Verifica seu classpath. Onde está sua classe PersistenciaGUI? Está em um JAR file? Como você está tentando rodar essa aplicação?

thiago.correa

brunorota:
qual seria o problema?

Eu importei os pacotes tudo certinho =/

Eu tinha pensado q era isso, mais eu fui v, eu importei os pacotes tudo certinho =/

Preste atenção no erro ele diz que não está achando a classe classes/help/PersistenciaGUI sendo que a sua classe está no pacote help/PersistenciaGUI!!!
Ele é do tipo RuntimeException ou seja, em tempo de execução, se você não tivesse importado teria dado um erro de compilação!

brunorota

Vo da um jeito nisso
Eu mudei o nome dos pacotes e me ferrei
Vo muda no linux tudo direitinho
Eh q no linux eh caseSensitive e no windows nao
Entao esta dando conflito no pacote Classes e classe.help
Ae eu mudei

Soh q pelo jeito nao funcionou =/

Bora pro linux de novo

Mais mto obrigado mesmo assim

Soh gostaria de saber pq deu esse erro sendo q eu importei os pacotes direitinho

Criado 6 de julho de 2009
Ultima resposta 6 de jul. de 2009
Respostas 6
Participantes 3