lundi 20 novembre 2017

Android/Java Reflection Class.getDeclaredFields() is not retrieving anything

I've been using reflection in android development since last year without any problems. After updating my Android Studio 3.0 I noticed that everything related to Reflection, that was working until then, just stopped working. I am no longer having success when trying to retrieve fields from a class using the method getDeclaredFields(), the result is always an empty array. After searching for almost a week, and trying a lot of different kind of stuff, I tried running a unit test with the code below, and it went well, but when I try to run the same code on an Activity, for example, I got no results, only the same old empty array.

Field[] fields = User.class.getDeclaredFields();
Log.d(HOME_ACITIVITY_TAG, "Count: " + fields.length);
for (Field field : fields)
     Log.d(HOME_ACITIVITY_TAG, "FieldName: " + field.getName());

Is there anyone who knows what is happening? Most of my project are depending on this, I used Reflection for almost everything.

Best Regards





Aucun commentaire:

Enregistrer un commentaire