I am trying to call a method from dex class using reflection but getting no such method exception when using arguments to call the method here is my code try {
Class<?> wordClass = dexClassLoader.loadClass("com.example.Algorithm");
Object iClass = wordClass.newInstance();
Method thisMethod = wordClass.getMethod("eoiValue",String.class );
helloTextView.setText("Hello " + thisMethod.invoke(iClass, "100").toString());
//The above 4 lines equals below
//helloTextView.setText("Hello " + new nfh.speeder.sample.gradle.hello.Word().speeder());
} catch (ClassNotFoundException e) {
} catch (NoSuchMethodException e) {
Log.i("exception","2");
} catch (IllegalAccessException e) {
} catch (IllegalArgumentException e) {
} catch (InvocationTargetException e) {
} catch (InstantiationException e) {
}
and the method I am calling is
public class Algorithm {
public String eoiValue (String temperature){
String eoi = "0";
float temp=Float.valueOf(temperature);
if (temp<=97){
eoi="0.1";
}
else if (temp<=98){
eoi="0.2";
}else if (temp<=99){
eoi="0.3";
}else if (temp<=100){
eoi="0.3";
}else if (temp<=101){
eoi="0.4";
}else if (temp<=102){
eoi="0.5";
}else if (temp<=103){
eoi="0.6";
}else if (temp<=104){
eoi="0.7";
}else if (temp<=105){
eoi="0.8";
}else if (temp<=106){
eoi="0.9";
}else if (temp<=107){
eoi="1.0";
}
return eoi;
}
}
I always get no such method exception.
Aucun commentaire:
Enregistrer un commentaire