Java error.lang.NoClassDefFoundError: Caused by: java.lang.ClassNotFoundException: when I execute.jar

I'm developing in the Netbeans IDE, when I run through the IDE everything works fine but when I perform the clean and build and create the .jar when running throws me this exception:

insert the description of the image here

I've tried compiling package by package but it still didn't work.

Any suggestions to fix this problem?

Edition this is the class that the error says is missing, I have already checked and the file .class is in the jar, does it have any error that the compiler does not can you catch it?

package gui.Admin;

import Models.Loteestado;
import java.util.ArrayList;
import java.util.List;
import javax.swing.table.AbstractTableModel;


public class LoteEstadoTableModelTESTE  extends AbstractTableModel{
    private List<Loteestado> lotes;

    private String[] colunas = new String[] {
            "lote","ok|nok","Produto","Qtd Total", "Qtd","Progresso"};


    public LoteEstadoTableModelTESTE() {
        lotes = new ArrayList<Loteestado>();

    }

    public LoteEstadoTableModelTESTE(List<Loteestado> lote) {
        lotes = new ArrayList<Loteestado>(lote);
        }



    @Override
    public int getColumnCount() {

        return colunas.length;
    }

    @Override
    public int getRowCount() {

        return lotes.size();
    }


    @Override
    public String getColumnName(int columnIndex) {

        return colunas[columnIndex];
    };


    @Override
    public Class<?> getColumnClass(int columnIndex) {

        switch (columnIndex) {
                case 0: 
                    return String.class;
                case 1: // RETURN OK OU NOK.
                    return String.class;                    
                case 2: //PRODUTO
                    return String.class;
                case 3: // MAX
                    return Integer.class;
                case 4: // REALIZADO
                    return Integer.class;
                case 5: // progress bar
                    return Integer.class;


        default:
            // Se o índice da coluna não for válido, lança um
            // IndexOutOfBoundsException (Exceção de índice fora dos limites).
            // Não foi necessário verificar se o índice da linha é inválido,
            // pois o próprio ArrayList lança a exceção caso seja inválido.
            throw new IndexOutOfBoundsException("columnIndex out of bounds");
        }
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {

        Loteestado lote = lotes.get(rowIndex);


        switch (columnIndex) {
        case 0:
            return lote.getLinha();
                case 1: //Primeira coluna é o nome.
                { String estado="";
                    if (lote.getQtdrealizada() > 10 && lote.getQtdrealizada() <= lote.getQtdtotal() / 2 && lote.getAlrinicio() == false)
            estado="NOK"; 
                    else if (lote.getQtdrealizada() > 10 && lote.getQtdrealizada() >= lote.getQtdtotal() / 2 && lote.getAlrfim() == false)
                        estado="NOK"; 
                    else estado="OK"; 

                    return estado;
                }
                case 2: // Primeira coluna é o nome.
            return lote.getProduto().getNoproduto();                     
        case 3: // Segunda coluna qtd realizada.
            return lote.getQtdtotal();
                case 4: // Segunda coluna é a qtd total.
            return lote.getQtdrealizada();
                case 5: // Segunda coluna é a qtd total.
            if(lote.getQtdtotal() != 0) return ((lote.getQtdrealizada() * 100) /lote.getQtdtotal());
                        else return 0;


                default:
            // Se o índice da coluna não for válido, lança um
            // IndexOutOfBoundsException (Exceção de índice fora dos limites).
            // Não foi necessário verificar se o índice da linha é inválido,
            // pois o próprio ArrayList lança a exceção caso seja inválido.
            throw new IndexOutOfBoundsException("columnIndex out of bounds");
        }
    }



    public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
            Loteestado lote = lotes.get(rowIndex);
            if (columnIndex == 0) {
                lote.setLinha(aValue.toString());
            }
            if (columnIndex == 2) {
                lote.getProduto().setNoproduto(aValue.toString());
            }
            if (columnIndex == 3) {
                lote.setQtdtotal((int)aValue);
            }
            if (columnIndex == 4) {
                lote.setQtdrealizada((int)aValue);
            }



        };


    @Override
    public boolean isCellEditable(int rowIndex, int columnIndex) {
        return false;
    }




    public Loteestado getlinha(int indiceLinha) {
        return lotes.get(indiceLinha);
    }


    //    public void ActuaLinha(){
//                linhas.set(removeLinha(indiceLinha), null)

  //      }

    public void addLinha(Loteestado linha) {
        // Adiciona o registro.
        lotes.add(linha);

        int ultimoIndice = getRowCount() - 1;

        fireTableRowsInserted(ultimoIndice, ultimoIndice);
    }


    public void removeLinha(int indiceLinha) {

        lotes.remove(indiceLinha);


        fireTableRowsDeleted(indiceLinha, indiceLinha);
    }

        public boolean IsContem(Loteestado lot){

           for(Loteestado lote:lotes)
           if(lote.getProduto().equals(lot.getProduto()))return true;

           return false;

        }


    public void addListaDeLinhas(List<Loteestado> linhass) {

        int tamanhoAntigo = getRowCount();

        lotes.addAll(linhass);


        fireTableRowsInserted(tamanhoAntigo, getRowCount() - 1);
    }

        public boolean procuraNome(Loteestado lote){

            if(lotes.contains(lote)){return true;}
            else {return false;}
        }

        public void actualizaLista(Loteestado lote){
            if(lotes.contains(lote)){
                for(Loteestado item : lotes){
                    if(item.equals(lote)) {lotes.set(lotes.indexOf(item), lote); fireTableRowsUpdated(lotes.indexOf(item), lotes.indexOf(item));}
                }

            }
            else {lotes.add(lote); fireTableRowsUpdated(lotes.indexOf(lote), lotes.indexOf(lote));}




        }

    public void limpar() {

        lotes.clear();

        fireTableDataChanged();
        }


    public boolean isEmpty() {
        return lotes.isEmpty();
    }

}

After that I make normal use of it:

jTblLinhasOnline.setModel(new LoteEstadoTableModelTESTE());

Can Aguem help me?

Issue 2

I copied the class to the Class SoftwareGui and it worked, however if anyone knows the other resolution I would prefer...

Author: jsantos1991, 2015-01-15

3 answers

In this case the problem was in the NetBeans cache.

This is the Directory:

C:\Users\jsan7os1991\AppData\Local\NetBeans\Cache\8.0

Must clean up all files.

 4
Author: jsantos1991, 2015-01-23 19:30:20

The exception NoClassDefFoundError is launched when the JVM is unable to find a certain class at runtime that was available at compile time, for example, if a method or any static member of a class is not available at the runtime, NoClassDefFoundError it's released.

It is important to understand that NoClassDefFoundError and ClassNotFoundException they are distinct exceptions, the latter is thrown when trying to load a class through the name, through the methods ForName from Class Class, loadClass e findSystemClass from class ClassLoader. This happens when no definition for the given class name was found.

Exception in thread "main" java.lang.NoClassDefFoundError:

This error is usually linked to classpath which may not be configured or referenced correctly. You have come to check if this problem happened to the specify the class path using the -classpath or -cp option?

It may also be likely that the cache data may have been corrupted due to some crash that the IDE suffered, this clearly justifies the strange behavior that Netbeans had according to this one comment.

In Bugzilla has something similar to this situation, but it occurs in another version(6.X), the solution found was the same as yours, eliminate the cache.

 2
Author: stderr, 2017-04-13 12:59:38

Looking at the consolation you pasted, JRE is complaining about the following Class:

gui.tabelaLinhasonline.TesteLoteEstadoTableModel

However, the code you pasted is of the following Class:

gui.Admin.LoteEstadoTableModelTESTE

Search your code for first class occurrences (the one that throws ClassNotFoundException) and replace with the second.

 0
Author: josivan, 2015-01-22 16:51:28