java - Reflection. Executing non-static method with parameters -


I need to perform some method through reflection

to execute the method

  Public Zero Certain Methods (int value 1, int value 2, string str, int well 3) {try {// some code} hold (exception e) {e.printStackTrace (); }}  

This execution code is

  executed public static zero ({{string string = "some.class"; string classpath = "something. .name "+": "+" some "class"; PathClassLoader loader = new Dalvik.system.PathClassLoader (classpath, classloader .getSystemClassLoader ()); class clause = class.formmen (classname, soul, loader); method method = Clazz.getDeclaredMethod ("some method", integer class, integer class, string class, integer class); object object = clause.New instance; Method.invoke (object, 1, 2, "str", 3);} hold (throbable e) {e.printStackTrace ();}}  

but I get an error

  01-22 21: 44: 52.286: W / System.err (10877): java.lang.NoSuchMethodException: Some method [class java.lang.Integer, class java.lang.Integer, class java.lang.String, class java .lang.Integer] 01-22 21:44: 52.286: W / Systems. ARR (10877): java.lang.Class.getConstructorOrMethod (Class Java: 472) 01-22 21: 44: 52.286: W / Systems . Er (10877): at java.lang Class I "text"> 

The method uses the manifesto some method primitive int parameter, so change the line that int class Instead of integer class:

  clazz.getDeclaredMethod ("some method", int.class, int.class, String.class, int.class);  

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -