I have a method that is calling another method within a jar. The calling method is:
public String nextView(JsonObject jsonObj) throws IOException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
System.out.println( "In next view" );
Class jsonObjClass = new JsonObject().getClass();
Class[] paramTypes = new Class[1];
paramTypes[0] = jsonObjClass;
System.out.println( jsonObjClass );
Method[] m = jarClass.getDeclaredMethods();
for (int i = 0; i < m.length; i++){
String name = m[i].getName();
Class[] params = m[i].getParameterTypes();
System.out.print( name + " has the parameters of " );
for(int j = 0; j < params.length; j++){
System.out.print(params[j] + " ");
}
System.out.println( "" );
Method thisMethod = jarClass.getMethod(name, params);
if(name == "nextView"){
System.out.println( "NEXT VIEW FOUND" );
Method nextViewMeth = jarClass.getMethod(name, paramTypes);
}
}
Its output is:
In next view
class com.google.gson.JsonObject
main has the parameters of class [Ljava.lang.String;
handshake has the parameters of
nextView has the parameters of class com.google.gson.JsonObject
NEXT VIEW FOUND
No such method
As you can see I have been trying to figure out what is wrong with my calling method, I have tried looping through all the methods in the jar to figure out if "nextView" is declared. Which it is, and then I print its parameters which is the JsonObject.class from google's gson. But when I try to call get method with those parameters, I get a no method found exception.
What can I do?
Aucun commentaire:
Enregistrer un commentaire