Re: Interpreting a string as a command
I've got it all working, but thanks for the advice. I also just got
private access working a moment ago:
Class tst = this.getClass();
try {
String fillin = "";
Method[] theMethods = tst.getDeclaredMethods();
for (int m=0; m<theMethods.length; m++) {
if (theMethods[m].getName().equals(theCommand)) {
theMethods[m].setAccessible(true);
fillin = ((String)theMethods[m].invoke(this));
}
}
toReply = toReply.replace(theCommand + "()", fillin);
} catch (Exception e) { e.printStackTrace(); }
Just had to invoke the Method immediately after setAccessible(true) or
it wouldn't work.
Ingo R. Homann wrote:
Hi,
jackroofman@gmail.com wrote:
java.lang.reflect.* seems promising, but I'm having a little trouble
figuring out exactly what to go with. As far as I can tell, I need a
Method, but it's throwing a NoSuchMethodException, despite the fact
that the Method does exist.
java.lang.NoSuchMethodException: com.sdd.BuildGUI.getMood()
with line 335 of com.sdd.BuildGUI saying:
private String getMood() {
Any idea what I'm missing?
In contrast to what Ian writes, I think, getMethod() should also find a
private method. Howeven, invoking this method should throw an Exception.
But you could solve that by calling setAccessible(true) first.
However, Ian is right - since you do not provide your Code, I cannot say
much to that.
Ciao,
Ingo