I'm following this article on Oracle Network to implement MVC when developing desktop applications.
I have a problem, though: I'm using an abstract Directory class extended by SimpleDirectory
and WildcardDirectory
. One of the model manager method accepts a Directory as argument:
public void addDirectoryDummy(Directory d){
System.out.println("Hello!");
}
The abstract controller uses a setModelProperty to call this method:
protected void setModelProperty(String propertyName, Object newValue) {
for (AbstractModel model: registeredModels) {
try {
Method method = model.getClass().
getMethod(propertyName, new Class[] {
newValue.getClass()
}
);
method.invoke(model, newValue);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
I call it from my actual controller like this:
public void dummy( Directory d){
setModelProperty( BACKUP_DUMMY, d );
}
In my view I have:
this.controller.dummy( new SimpleDirectory(0,"ciao") );
I have the following error:
java.lang.NoSuchMethodException: it.univpm.quickbackup.models.BackupManager.addDirectoryDummy(it.univpm.quickbackup.models.SimpleDirectory)
at java.lang.Class.getMethod(Class.java:1605)
How do I solve this problem? I'm missing something in the usage of getMethod
.
EDIT: I've read the docs and in getMethod
it says
The parameterTypes parameter is an array of Class objects that identify the method's formal parameter types, in declared order.
So I'm guessing that's the problem.