ReflectionAPI-class.getMethod(x,String.class)error in JRE7 | Selenium Forum
M
Posted on 11/02/2016
I was trying to go through Reflection API video and code and i getting Error on following line

Method method=ReflectionAPI.class.getMethod(x, String.class);

here is the error:
The method getMethod(String, Class[]) in the type Class is not applicable for the arguments (String, Class)

can anyone help on how to resolve this error?

M
Replied on 11/02/2016

send your entire code


M
Replied on 12/02/2016

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



public class ReflectionAPI {

public static void main(String[] args) throws SecurityException, NoSuchMethodException {
// TODO Auto-generated method stub
String x = "sampleTest";
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);
}

}


M
Replied on 12/02/2016

use this

[code:1x0ojny1]package com.sample;

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

public class ReflectionAPI {

public static void main(String[] args) throws SecurityException,
NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
// TODO Auto-generated method stub
String x = "sampleTest";
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);
}

}
[/code:1x0ojny1]


M
Replied on 15/02/2016

It still gives same error on getMethod:

The method getMethod(String, Class[]) in the type Class is not applicable for the arguments (String, Class)


M
Replied on 15/02/2016

please check all the jdk .

Responsive image