0


package com.mycompany.dataclass;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;

public class DataClass {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        // Obtener la lista de archivos .class de la carpeta
        File folder = new File("E:\\ruta\\arcchivosclass");
        File[] listOfFiles = folder.listFiles();

        for (File file : listOfFiles) {
            if (file.isFile() && file.getName().endsWith(".class")) {
                // Cargar la clase utilizando un ClassLoader
                URLClassLoader classLoader = URLClassLoader.newInstance(new URL[] { folder.toURI().toURL() });
                Class<?> cls = classLoader.loadClass(file.getName().replace(".class", ""));

                // Obtener información de los métodos de la clase
                Method[] methods = cls.getDeclaredMethods();
                for (Method method : methods) {
                    System.out.println("Nombre del método: " + method.getName());
                    System.out.println("Tipo de retorno: " + method.getReturnType().getName());
                    System.out.println("Entradas: ");
                    for (Class<?> parameterType : method.getParameterTypes()) {
                        System.out.println(" - " + parameterType.getName());
                    }
                    System.out.println("Salidas: ");
                    for (Class<?> exceptionType : method.getExceptionTypes()) {
                        System.out.println(" - " + exceptionType.getName());
                    }
                }
            }
        }
    }
}

The problem

Exception in thread "main" java.lang.NullPointerException: Cannot read the array length because "" is null at com.mycompany.dataclass.DataClass.main(DataClass.java:19) Command execution failed. org.apache.commons.exec.ExecuteException: Process exited with an error: 1 (Exit value: 1)

Hugo Reyes
  • 11
  • 1
  • Your app can't read "arcchivosclass". We can't tell why, since we have no information about your setup. – Tom Dec 21 '22 at 18:52
  • the path in brackets " " is an example, the folder path is correct. I tried to read the files with .class extension, a .class file that contains something simple and if it shows me what is requested, but when it is a more advanced and extensive .class file it gives me that error. – Hugo Reyes Dec 21 '22 at 19:10

0 Answers0