【发布时间】:2013-12-30 18:42:37
【问题描述】:
所以,我写了这些类:
public class FicherosDeCiudadanos {
public static int numCiudadanos (File f) {
try{
Scanner texto=new Scanner(f);
int contador=0;
while(texto.hasNextLine()){
contador++;
texto.nextLine();
}
texto.close();
return contador;
}
}
public static Ciudadano[] leerFichero (File f) {
try{
Scanner texto=new Scanner(f);
//This next line throws classNotFound when debbugging but only
//when evaluating Ciudadano[]
Ciudadano[] tablaCiudadano = new Ciudadano[numCiudadanos(f)];
....
//TO-DO
}
}
我验证它有效,并且确实有效,leerFichero() 方法完美地完成了这项工作。它使用 TO-DO 中的代码创建了一个 Ciudadano 的对象数组。但是,在另一个包中,我调用方法leerFichero(),它到达那里,计算出numCiudadanos() 来设置数组的长度,但是当它到达Ciudadano[] 时,它抛出ClassNotFoundException,然后程序停止。当我从它自己的包中使用它时它仍然有效。
我猜这是堆栈
Thread [main] (Suspended)
owns: Object (id=36)
owns: Object (id=37)
ClassNotFoundException(Throwable).<init>(String, Throwable) line: 286
ClassNotFoundException(Exception).<init>(String, Throwable) line: not available
ClassNotFoundException(ReflectiveOperationException).<init>(String, Throwable) line: not available
ClassNotFoundException.<init>(String) line: not available
URLClassLoader$1.run() line: not available
URLClassLoader$1.run() line: not available
AccessController.doPrivileged(PrivilegedExceptionAction<T>, AccessControlContext) line: not available [native method]
Launcher$ExtClassLoader(URLClassLoader).findClass(String) line: not available
Launcher$ExtClassLoader(ClassLoader).loadClass(String, boolean) line: not available
Launcher$AppClassLoader(ClassLoader).loadClass(String, boolean) line: not available
Launcher$AppClassLoader.loadClass(String, boolean) line: not available
Launcher$AppClassLoader(ClassLoader).loadClass(String) line: not available
FicherosDeCiudadanos.leerFichero(File) line: 54
Operaciones.nombreCliente(int) line: 80
Operaciones.listadoCompras() line: 37
TrabajoProg1.ejecutarOperacion(int) line: 40
TrabajoProg1.main(String[]) line: 22
【问题讨论】:
-
发布异常的堆栈跟踪。
-
请验证调用者(代码调用“leerFichero”)是否在其类路径中正确导入类 Ciudadano。
标签: java classnotfoundexception