Using java.lang.reflect.Parameter in android applications

0

Hello. I'm trying to implement an android application (with the Android Studio IDE) that uses Reflections to access certain attributes of a class. However, when using the java.lang.reflect.Parameter class in versions lower than 26 (Android 8.0) the application closes and gives error (NoSuchMethodException) My question is, I can not use the properties of this class in versions prior to 26 ??? And is there a "substitute"?

    
asked by anonymous 28.05.2018 / 19:55

1 answer

1

What was causing error was a method of class java.lang.reflect.Method ( getParameters() , which returns an array of parameters corresponding to the method).

Parameter[] parameters = meumetodo.getParameters();

I changed my code to return only the list of parameter types (through the method, getParameterTypes ()), thus returning me to an array of classes corresponding to the parameter types.

Class<?>[] parameterTypes = meumetodo.getParameterTypes();

I did not find much information on the internet about this error, only what Android Studio itself informed me (the minimum API to use the Parameter class should be 26 or later). Below is the error message when I use Parameter:

    
29.05.2018 / 13:59