Error on Reflection API | Selenium Forum
M
Posted on 29/11/2015
Hello there,

Below is the code written for Reflection API. I am getting error. Please take a look and help me out.

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


public class Reflections {

public static void main(String[] args) throws SecurityException, NoSuchMethodException, ReflectiveOperationException
{

String x="SampleTest";

Method method= ReflectionAPI.class.getMethod(x, String.class);
method.invoke(method, "Hello");
}

public static void SampleTest(String x){
System.out.println("In SampleTest Method "+x);
}

}

M
Replied on 29/11/2015

what is the error?


M
Replied on 01/12/2015

It gives the error line at Method method= ReflectionAPI.class.getMethod(x, String.class);
When I run the code - it gives the below error



Exception in thread "main" java.lang.Error: Unresolved compilation problem:
ReflectionAPI cannot be resolved to a type


M
Replied on 01/12/2015

use this. class name has to be same as method name


[code:ym0soz1r]package com.soapuitutorial.propertie;
import java.lang.reflect.Method;


public class Reflections {

public static void main(String[] args) throws SecurityException, NoSuchMethodException, ReflectiveOperationException
{

String x="SampleTest";

Method method= Reflections.class.getMethod(x, String.class);
method.invoke(method, "Hello");
}

public static void SampleTest(String x){
System.out.println("In SampleTest Method "+x);
}

}


[/code:ym0soz1r]