The array of Class objects passed to getMethod() should be equal in length to the number of arguments of the method you want to call, and the Class arguments themselves should represent the types of those arguments. In your code, the number of Class objects is always equal to the number of TextFields, and they are always String.class. Therefore you'll only be able to find and call methods that have the same number of arguments as you have TextFields, and only if all the arguments are supposed to be Strings. Presumably few methods meet those criteria, so most of the time you'll get a MethodNotFoundException.
I don't see anything that suggests this code will try to invoke more than one method, but who knows what happens outside of the code you've shown us.
As far as your number 2: it's not at all an easy problem. Many of your argument Strings will be ambiguious: the String "27" could validly be an int, an Integer, a long, a Long, a Short, a short, a byte, a Byte, an Object, etc. So you have to start from the Method objects, find out what parameter types they accept, and then work backwards to see if the Strings you have can be converted to those types. And don't forget that methods can be overloaded: for any given method name, you would have to look at all the methods of that name and try to match their argument lists against the Strings you have to work with. In the general case, it's a fairly hard problem; expect to write a decent chunk of code to solve it.
Note that scripting environments for Java do exist, so if this has some purpose, as opposed to just being a learning exercise, you might want to try to embed one of them and use its existing code that does this. Check out "BeanShell", "Groovy", and "Jython", if you're interested.
Here is an an interpreter I made to play with reflection. It has simple rules for inferring datatypes, but relies on the user to give hints at times. For example to indicate 27 is a String they'd have to type "27" with quotes. See Argument and Reflector for bits that may be of most interest.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Think of how stupid the average person is. And how half of them are stupider than that. But who reads this tiny ad?
Free, earth friendly heat - from the CodeRanch trailboss