I'm testing with Java reflection and trying to apply overloaded method to parameters according to their type..
However, I have NoSuchMethodException even though the method I tried to get is public. This exception still appears when I used getDeclaredMethod.
Here's the main program
public class Test {
    public static void main(Object... inputs){
        InputManipulation test = new InputManipulation();
        for (Object input: inputs){
            Class ownerClass = test.getClass();
            Class inputClass = input.getClass();
            Method method = ownerClass.getDeclaredMethod("add", inputClass);
            method.invoke(test, "Testing reflection");
        }
    }
}
And here's the self-defined InputManipulation class
public class InputManipulation {
    Integer total;
    public InputManipulation(){this.total = 0;}
    public void add(Integer num){this.total += num;}
    public void add(String str){System.out.println(str);}
}
Thanks in advance!
I now changed the Test class as follows.. but the problem still exists.
public class Test {
    public static void main(String[] args){
        Test testExample = new Test();
        testExample.testMethod("String1", 1, "String2");
    }
    public void testMethod(Object... inputs){
        InputManipulation test = new InputManipulation();
        for (Object input: inputs){
            Class ownerClass = test.getClass();
            Class inputClass = input.getClass();
            Method method = ownerClass.getDeclaredMethod("add", inputClass);
            method.invoke(test, "Testing reflection");
        }
    }
}
I also tried putting the inputClass into an array of Class, as suggested by another post, but it didn't help..
                        
There seems to be a few issues with the initial code you provided and as others have suggested using an IDE would have pointed some of the issues out pretty quickly. However, I have taken your update and fixed the code to call the proper method in the loop you provided of input types.
First change your InputManipulation class like so:
Now alter your Test class like so:
I used these readings to help guide my answer, but altered the way I invoked the method:
http://tutorials.jenkov.com/java-reflection/methods.html