java.lang.Noclassdeffounderror: Caused by: java.lang.Classnotfoundexception: When run . jar

Asked

Viewed 14,619 times

4

I am developing in Netbeans IDE when running through the IDE everything works fine but when I do clean and build and create . jar while executing casts me this exception:

inserir a descrição da imagem aqui

I tried to compile package by package but it still didn’t work.

Any suggestions to fix this problem?

Editing this is the class that the bug says is missing, I already checked and the file . class is in the jar, Is there an error that the compiler cannot catch?

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());

Hang on, you can help me?

Issue 2

I copied the class for the class SoftwareGui and it worked, yet if anyone knew the other resolution they preferred...

  • The class gui.tabelasLinhasonline.TesteLoteEstadoTableModel is there? Is it in a JAR in the classpath? Is there a capitalization error on it (this capital L in the package name is suspicious)? Is there a typo in it (eg it should be Linha instead of Linhas)?

  • @Victor no. jar that creates this class is there, in one of the attempts to solve the problem I changed her name "Testeloteestadotablemodel" and I saw that I had a problem because the word started with lowercase letter, I corrected but gave the same error again... However I will re-examine this possibility of typo

  • @Victor I’ve changed the name, I’ve changed the board of this class, I’ve copied it to a new class with a different name but still I’m not getting it, I don’t understand why

  • Then post the code of GUI.SoftwareGUI to make sure she doesn’t do anything too bizarre. But before that, it’s worth recompiling everything from scratch with a clean environment.

  • @Victor "clean environment" what do you mean? create a new project and send this one inside? I am now thinking about another possible problem I started this project in netbeans 7 and now I am working on 8 on another computer will be may be this?

  • Clean environment means to erase all ". class" and all jars that are generated by the compilation process. Finally have only the sources, classpath Jars and other necessary files that the compiler does not use (such as pom.xml, figures, configuration files, etc).

  • Everything goes wrong, in netbenas there is an option that says "inspect" only for that I had to install a "plugin" now netbeans does not start large mer***... these files . class are in the right "build" folder?

  • Just giving a "Clean and Build" should be enough. You don’t need any plugin for this. But yes, they should be in the folder build. And the Jars generated in the folder dist. Delete everything inside these folders, leaving them empty.

Show 3 more comments

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 must be cleaned.

2

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

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

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

This error is usually linked to classpath which may not be configured or referenced correctly. You even checked if this problem happened by specifying the class path using the option -classpath or -cp?

It may also be likely that the cache data might have been corrupted due to some Crash that the IDE suffered, it clearly justifies the strange behavior that Netbeans has had according to his commenting.

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

0

Looking at the solace you’ve glued, the JRE is complaining of the following class:

gui.tabelaLinhasonline.TesteLoteEstadoTableModel

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

gui.Admin.LoteEstadoTableModelTESTE

Search your code for occurrences from the first class (the one you launch ClassNotFoundException) and replace by the second.

  • well observed, but that was not the problem, the names are different because when the error happened and I published it I received the help of the Victor to say to verify if the name was correct or else there were some problems with the uppercase or lowercase letters, and in an attempt to verify that I changed the names, however it did not solve the problem, but as I was always pointing to that class I decided to post here if it were not sometimes to be doing some barbarity with it that the compiler does not catch up.... Hence names different yet thanks for trying to help

  • Ok. Have you created an innerclass? You can reproduce the previous error but with the environment (code) updated?

  • Yes after I created innerclass this error no longer appeared, but there were others like this pointing to other classes, so after some research I saw that it was a problem of the netbeans cache, when I cleaned everything was solved...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.