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)