gpt4 book ai didi

java - Netbeans 中的 ClassNotFoundException

转载 作者:行者123 更新时间:2023-11-30 06:07:48 24 4
gpt4 key购买 nike

我的项目中有这些包:

I have this packages in my project

在 AnalysisLab 类中调用 File_Intestazione 时,出现 ClassNotFoundException。看一下这段代码:

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

所以,当我执行我的程序时,我遇到了这个异常(exception):

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)

最佳答案

它正在不同的包中寻找具有该名称的类:

java.lang.ClassNotFoundException: analysislab.File_Intestazione

您的类(class)是ServicesFiles.File_Intestazione

此错误应该在全新重建中显示为编译错误(如果确实存在),但看起来上面的代码正在读取某种过时的序列化对象类定义。

删除/重新创建那些序列化的对象文件,它应该可以工作。

关于java - Netbeans 中的 ClassNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50925460/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com