Вопрос

So, I wrote these class:

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
   }
}

I verified it worked, and it did, the method leerFichero() did the job perfectly. It created an object array of Ciudadano with the code in TO-DO. But then, in another package, I call the method leerFichero() and it gets there, works out numCiudadanos() to set the lenght of the array, but then when it gets to Ciudadano[] it throws ClassNotFoundException, and the program stops. It still works when I use it from its own package.

I'm guessing this is the stack

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    
Это было полезно?

Решение 3

So, in the end that error meant nothing, there was another error later which made it seem like it stopped with this one.

Другие советы

This could be a build path problem. You need to right-click on the outside package and go to

Build Path > Configure Build Path

and navigate to

Projects

Then, you click Add... and add the project containing FicherosDeCiudadanos.

Make sure at the top of your calling class there is the line:

import package1.FicherosDeCiudadanos

Where package1 is the package containing FicherosDeCiudadanos

Sometimes the debugger is out of sync with some classes.

Try to Clean/Build project and even relaunch Eclipse (Or other IDE). Then try debugging again.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top