Reputation: 494
[ note: i'm beginner in java ]
I try to call object by name and then I try to call its method by name,
but this code throws exception java.lang.NoSuchMethodException:
Field mainClassField = mainObject.getClass()
.getField( dataObject.callObject );
/* callObject is an another object */
Object callObject = mainClassField.get( mainObject );
Method callMethod = callObject.getClass()
.getMethod( dataObject.callMethod ); << error on this line
callMethod.invoke(callObject, dataObject);
[ note: i pass dataObject from actionscript 3 through AMF ]
calling object code:
public class UserCallController extends Controller {
public void getUserById(DataTransferObject dataObject) {
Ppvchat mainClass = _inst._mainClass;
dataObject.data.put("userData",
mainClass.userModel.getById( dataObject.data.getString("id") ));
}
}
thanks.
Upvotes: 0
Views: 88
Reputation: 115378
If NoSuchMethodException
such method indeed does not exist.
So, check the following.
Anyway your code seems wrong.
callObject.getClass().getMethod( dataObject.callMethod );
means that you think that method does not have arguments.
callMethod.invoke(callObject, dataObject);
means that you think that this method has argument assignable from dataObject
.
Upvotes: 2