jeudi 29 juin 2017

Java Reflection NoSuchMethodException when referencing a method in same class

I am experiencing a NoSuchMethodException when trying to call getMethod on a method in the same class with no arguments from a string name pulled from a hashmap. Any advice? The call to get the method is here:

if (testChoices.containsKey(K)) {
        String method = testChoices.get(K);
        System.out.println(method);

        try {
            java.lang.reflect.Method m = TST.getClass().getMethod(method);
            m.invoke(testChoices.getClass());
        } catch (NoSuchMethodException e1) {
            // TODO Auto-generated catch block
            System.out.println("No method found");
            e1.printStackTrace();
        } catch (SecurityException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();


        } catch (IllegalAccessException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IllegalArgumentException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();

One of the methods I am trying to call is here:

private static void testgetDomainLic() throws IOException {

And the map entry being called is here:

testChoices.put(1, "testgetDomainLic");





Aucun commentaire:

Enregistrer un commentaire