Search code examples
javaexceptionnetbeansclassnotfoundexception

ClassNotFoundException in Netbeans


I Have these packages in my project:

I have this packages in my project

I have a ClassNotFoundException when in AnalysisLab class i call File_Intestazione. Look at this code:

import ServicesFiles.File_Intestazione;
import java.io.FileNotFoundException;
import java.io.IOException;

public class AnalysisLab
{        
    public static void main(String[] args)
    {
        try
        {
            new AnalysisLab().verifica_licenza();
        }
        catch(FileNotFoundException e){JOptionPane.showMessageDialog(null,"Impossibile trovare il file intestazione.dat"); System.exit(0);}
        catch(IOException e){JOptionPane.showMessageDialog(null,"Errore durante la lettura da file intestazione.dat"); System.exit(0);}
        catch(ClassNotFoundException e){JOptionPane.showMessageDialog(null,"ClassNotFoundException"); e.printStackTrace(); System.exit(0);}
    }

    public void verifica_licenza() throws FileNotFoundException, IOException, ClassNotFoundException
    {
        File_Intestazione fIntestazione = new File_Intestazione();
    }
}

So, when i execute my program i have this exeption:

java.lang.ClassNotFoundException: analysislab.File_Intestazione
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at java.io.ObjectInputStream.resolveClass(ObjectInputStream.java:686)
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1866)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1749)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2040)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1571)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:431)
at ServicesFiles.File_Intestazione.<init>(File_Intestazione.java:26)
at Temp.AnalysisLab.verifica_licenza(AnalysisLab.java:42)
at Temp.AnalysisLab.main(AnalysisLab.java:25)

Solution

  • It's looking for the class with that name in a different package:

    java.lang.ClassNotFoundException: analysislab.File_Intestazione
    

    Your class is ServicesFiles.File_Intestazione.

    This error should show up as a compile error in a fresh rebuild (if it's there at all), but it looks like the code above is reading some kind of serialized object with the out of date class definition.

    Delete / recreate those serialized object files, and it should work.