Using java.lang.reflect.Parameter in android applications

Asked

Viewed 36 times

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 class java.lang.reflect.Parameter in versions below 26 (Android 8.0) the application closes and gives error (Nosuchmethodexception) My question is, can I not use the properties of this class in versions prior to 26??? And by chance there is a "substitute"?

  • You can post the code?

  • This method only exists in JAVA 8. Only part JAVA 8 is supported on older versions of Android.

1 answer

1

What was causing error was a class method 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 getParameterTypes() method), thus returning me to an array of classes corresponding to the parameter types.

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

I didn’t find much information on the internet about this error, only what Android Studio informed me (the minimum API to use the Parameter class must be 26 or later). Below the error message when I use Parameter:

inserir a descrição da imagem aqui

Browser other questions tagged

You are not signed in. Login or sign up in order to post.