沿的線,所以,我已經得到的東西:NoSuchMethodException問題與反思
public abstract class myClass {
String myString;
int test;
public myClass(String heuristic) {
mystring = heuristic;
test = heuristicSwitch();
}
public int heuristicSwitch() {
int hTest = 0;
try {
String methodName = "getHeuristic" + myString;
Method actionMethod = myClass.class.getDeclaredMethod(methodName);
hTest = (Integer)actionMethod.invoke(this);
}
catch(Exception e) {
}
return hTest;
}
public int getHeuristicManhattan() {
return 100;
}
}
我難倒...我不斷收到NoSuchMethodException
,但我不知道爲什麼。我認爲這個問題可能是因爲myClass是抽象的,所以我嘗試了getClass()並且有相同的異常,所以我認爲它是別的東西(除非這找不到超類方法?)。思考?
這樣做,謝謝!我會盡快投票。 – bendicott 2011-04-14 18:05:58