I'm learning java reflection. I am using the following code. But when I run, it gives the error unreported exception ClassNotFoundException; must be caught or declared to be thrown Class className=Class.forName("First"); Maybe I'm going wrong somewhere. Please help me out. Here's the code:
import java.lang.reflect.Method;
public class First{
public void print(){}
public void ready(){}
}
public class test{
public static void main(String args[])
{
Class className=Class.forName("com.Test.First");
Method[] methods=className.getMethods();
System.out.println("First method is" + methods[0]);
}
}
Aucun commentaire:
Enregistrer un commentaire