mercredi 12 décembre 2018

correct use of reflection to get a Class method

I try to implement the recommendation made in item #11 of issue 111316656 that says:

You should also be able to use reflection to get access to the FloatingActionButtonImpl backing the fab, and then call setImageMatrixScale(1) on that instance.

with the following code:

            FloatingActionButton fab;
            ...    
            Method method = null;
            try {
                method = fab.getClass().getMethod("setImageMatrixScale", null);
                method.invoke(fab, 1);
            } catch (NoSuchMethodException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            } catch (InvocationTargetException e) {
                e.printStackTrace();
            }

But the NoSuchMethodException is raised. What is the problem?





Aucun commentaire:

Enregistrer un commentaire