There are several classes of the form:

package ru.com.project.service; public class Hashing { public static String Hash ( String data ) { return data; } } 

I'm trying to call the method of the desired class by the name:

 String serviceName = "Hashing"; String serviceMethod = "Hash"; Class service = Class.forName( "ru.com.project.service." + serviceName ); Method classMethod = service.getMethod( serviceMethod ); 

The class is located, and return

 service.getMethods() 

there is a required method, but on the line

 Method classMethod = service.getMethod( serviceMethod ); 

a mistake falls

(java.lang.NoSuchMethodException) java.lang.NoSuchMethodException: ru.project.service.Hashing.Hash ()

What he doesn't like, I don't understand ...

    1 answer 1

    Use another method . Pass the parameter types of this method and will work. Now you are trying to find a method without parameters.

    • Then it is strange that it throws an exception, and does not return null . Thank. - t1nk
    • The documentation says that the error is thrown , the behavior is predictable - Vitalii Kravchenko