Note that there are some explanatory texts on larger screens.

plurals
  1. POReflection in Android is not working
    primarykey
    data
    text
    <p>I tried using reflection to use a custom List View for an App with target api level 7. The necessary fileds are only available from api level 9 so I attempted to fix that via reflection. </p> <p>I need to find the protected Method View.overScrollBy( int,int,int,int,int,int,int,int,boolean). When i call </p> <pre><code>View.getDeclaredMethods() </code></pre> <p>and iterate over the Method[] array i find it, but when I try </p> <pre><code>View.class.getDeclaredMethod(String name, Class...&lt; ? &gt; paramTypes) </code></pre> <p>I get a NoSuchMethodException. I compared the hard coded Method Name and parameterType values with the values extracted from the method (found via iteration) and they are identical...</p> <pre><code>private boolean initCompatibility() { Method[] methods = View.class.getDeclaredMethods(); try { // The name of the Method i am looking for; String OVERSCROLL_S = "overScrollBy"; for (Method meth : methods) { if (meth.getName().equals(OVERSCROLL_S)) { mListView_overScrollBy = meth; break; // method found } } // Params for getDeclaredMethod(…) String methodName = "overScrollBy"; Class[] methodParams = { Integer.TYPE, Integer.TYPE, Integer.TYPE, Integer.TYPE, Integer.TYPE, Integer.TYPE, Integer.TYPE, Integer.TYPE, Boolean.TYPE }; // works Method test = View.class.getDeclaredMethod(methodName,methodParams); // fails View.class.getDeclaredMethod(mListView_overScrollBy.getName(), mListView_overScrollBy.getParameterTypes()); /* * I also tried this way around and again the first worked and the second * failed, so the input arguments are not the problem... * View.class.getDeclaredMethod( mListView_overScrollBy.getName(), * mListView_overScrollBy.getParameterTypes() ); * Method test = View.class.getDeclaredMethod(methodName,methodParams); */ return true; } catch (SecurityException e) { e.printStackTrace(); return false; } catch (NoSuchMethodException e) { e.printStackTrace(); return false; } } </code></pre> <p>I do not understand why the call always works the first time and the does not the second time. Interestingly it also fails when i call only once for View.class.getDeclaredMethod(String name, Class...&lt; ? > paramTypes) and it does not make any difference whether i use the hard coded input values or the one extracted from the method I am looking for...</p> <p>Does anybody know what the problem is? Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload