The code for ReflectionAPI is giving an error with jre1.8.0 | Selenium Forum
M
Posted on 10/01/2016
I have tried a code on reflection API, but it is giving an error everytime.

Then i copied Ashish's code but again i am getting the error.

Below is the code and the error.

Please give a detailed answer as I am new to selenium and java :roll:

Code:

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

// calling method whose name we store in a variable
public class ReflectionAPI {

public static void main(String[] args) throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException {
//sampleTest("xxxXX");
String x="sampleTest";
//String meth=read name from xls file
Method method= ReflectionAPI.class.getMethod(x, String.class);
method.invoke(method, "hello");


System.out.println("end");
}

public static void sampleTest(String x){
System.out.println("in sample test-- "+x);
}

}


Error

Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The type java.lang.reflect.AnnotatedElement cannot be resolved. It is indirectly referenced from required .class files
The method getMethod(String, Class[]) in the type Class<T> is not applicable for the arguments (String, Class<T>)
The method invoke(Object, Object[]) in the type Method is not applicable for the arguments (Method, String)

at ReflectionAPI.main(ReflectionAPI.java:11)

M
Replied on 10/01/2016

its working for me please check all the jar files.