0

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    
2
  • 2
    Post the stacktrace of the exception. Commented Dec 27, 2013 at 8:13
  • 1
    Please verify if the caller (where the code call "leerFichero") has correctly import the class Ciudadano in its classpath. Commented Dec 27, 2013 at 8:22

3 Answers 3

1

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

Sign up to request clarification or add additional context in comments.

7 Comments

Both packages are in the same project. And the build path includes all packages in the project
what is line 54 in leerFichero()?
Ciudadano[] tablaCiudadano = new Ciudadano[numCiudadanos(f)];
the classes Ciudadano and FicherosDeCiudadanos are in the same package and still, both are imported in the class that calls the method leerFichero(). Sorry if I'm difficult to understand
Make sure that the original file for Ciudadano is still accessible from inside Eclipse. It might be that your workspace has "forgotten" where it is, and needs it to be re-imported.
|
1

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.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.