Error java.lang.NoClassDefFoundError: Caused by: java.lang.ClassNotFoundException: When I execute .jar

4

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

Ihavetriedtocompilepackagebypackagebutitstilldidnotwork.

Anysuggestionstofixthis?

Editingthisistheclassthattheerrorsaysismissing,Ialreadycheckedandthe.classfileisinthejar,Isthereanyerrorthatthecompilercannotget?

packagegui.Admin;importModels.Loteestado;importjava.util.ArrayList;importjava.util.List;importjavax.swing.table.AbstractTableModel;publicclassLoteEstadoTableModelTESTEextendsAbstractTableModel{privateList<Loteestado>lotes;privateString[]colunas=newString[]{"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 ...

    
asked by anonymous 15.01.2015 / 12:52

3 answers

4

In this case the problem was in the netbeans cache.

This is the directory:

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

All files should be cleaned.

    
20.01.2015 / 09:47
1

The exception NoClassDefFoundError is thrown when is not able to find a certain class at runtime that was available at compile time, exemplifying, if a method or any static member of a class is not available in runtime , NoClassDefFoundError is thrown.

It's important to understand that NoClassDefFoundError and ClassNotFoundException are distinct exceptions, the latter is thrown when attempting to load a class through the name, using methods ForName of class Class , loadClass and findSystemClass of 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 . / a> which may not be properly configured or referenced. Did you even check to see if this problem occurred by specifying class path using the -classpath or -cp option?

It may also be likely that the cache data may have become corrupted due to some Crash than the IDE has suffered, this clearly justifies the strange behavior that Netbeans had under its comment .

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

    
24.01.2015 / 01:40
0

Looking at the console you've pasted, the JRE is complaining about the following class:

gui.tabelaLinhasonline.TesteLoteEstadoTableModel

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

gui.Admin.LoteEstadoTableModelTESTE

Look in your code for occurrences of the first class (which throws ClassNotFoundException ) and replace with the second.

    
22.01.2015 / 17:51