Code: Select all
{
t.getP().getName()
t.getP().getAge()
t.getP().getLocation()
}
< /code>
und das folgende Java -Programm: < /p>
public class Test {
private Person p;
public Test(){
p = new Person("Jhon", "19", "New York", "Mathematician");
}
public Person getP() {
return p;
}
public static void main(String[] args) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException{
Test t = new Test();
// Read txt file with methods
String line1 = "t.getP().getName()";
String line2 = "t.getP().getAge()";
String line3 = "t.getP().getLocation()";
// Execute methods
Method m = t.getClass().getMethod(line1);
m.invoke(t);
}
}
< /code>
Ich erhalte den folgenden Fehler: < /p>
Exception in thread "main" java.lang.NoSuchMethodException: Test.t.getP().getName()()
at java.lang.Class.getMethod(Class.java:1786)
at Test.main(Test.java:24)