samedi 7 février 2015

Class not found exception

I am learning reflection in Java. I came to know that we can easily extract methods used in a class file with reflection.


I have a java class file which has n number of methods.


Test file refers to the java class from where I want to read the methods used and testSample is my class from where I am accessing Testfile class methods



public class testSample
{

public static void main(String args[]) throws ClassNotFoundException

{

File filename = new File(
"C:/ProgramData/Eclipse/Projects_3.7.1/Testfile.java");

String filen = filename.toString();

if (filen.endsWith(".java"))

{

String actfilename = StringUtils.substringBefore(filen, ".java");

Class classname = Class.forName(actfilename);

Method[] method = classname.getMethods();

for (Method methods : method)

{

System.out.println("Method name \r\n" + methods.getName());

Class[] parameters = methods.getParameterTypes();

for (Class parametername : parameters)

{

System.out.println("parameters name \r\n"
+ parametername.getName());

}

}

}

}
}


Please help me out of this.. I am pasting the entire code so that it could be easy for you to identify my problem.


Thanks in advance.






Aucun commentaire:

Enregistrer un commentaire