Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6782103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:42:06+00:00 2026-05-26T16:42:06+00:00

I tried using reflection to use a custom List View for an App with

  • 0

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.

I need to find the protected Method View.overScrollBy( int,int,int,int,int,int,int,int,boolean). When i call

View.getDeclaredMethods() 

and iterate over the Method[] array i find it, but when I try

View.class.getDeclaredMethod(String name, Class...< ? > paramTypes)

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…

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;
    }
}

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…< ? > 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…

Does anybody know what the problem is? Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T16:42:07+00:00Added an answer on May 26, 2026 at 4:42 pm

    This is very interesting, but it is not Android-specific, I think.

    I wrote this small test in plain Java:

        public class ReflectionTest {
    
            public static void main(String[] args){
                Method[] m = ReflectionTest.class.getDeclaredMethods();
                for (Method method : m) {
                    System.out.println(method.getName());
                }               
    
                try {
                    Method m1 = ReflectionTest.class.getDeclaredMethod("d0", int.class, boolean.class);
                    if(m1 != null){
                        System.out.println("m1 found!");
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                } 
    
                try {
                    Method m2 = ReflectionTest.class.getDeclaredMethod("d0", Integer.TYPE, Boolean.TYPE);
                    if(m2 != null){
                        System.out.println("m2 found!");
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                } 
    
                try {
                    Class<?>[] carr = m[1].getParameterTypes();
                    Method m3 = ReflectionTest.class.getDeclaredMethod("d0", carr);
                    if(m3 != null){
                        System.out.println("m3 found!");
                    }
                } catch (Exception e){
                    e.printStackTrace();
                } 
            }
    
            public void d0(int a, boolean b){
    
            }
        }
    

    In eclipse, if I debug it, the three m1,m2 and m3 are printed. However, if I run it, a NoSuchMethodException is thrown when trying to get m3.

    UPDATES:

    • Tested running with jre 7 under linux, and all three m1,m2 and m3 were printed. Perhaps is a problem with jre6? Or is eclipse run configuration?
    • Changed carr declaration to use method 0 instead of 1: Class<?>[] carr = m[0].getParameterTypes(); as Gray suggested. Now it runs ok but throws exception in debug mode. This means different method order for the returned array m.
    • Update #2 confirmed, I’ve included a for loop to print the method names. In run mode the order of the method array is reversed compared to debug mode.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In WinForms, I'd use Application.ProductVersion . I've tried using System.Reflection.Assembly in various ways but
I tried using height: 100% but this makes the div only as high as
I tried using Exist and IN. Not only did I not succeed, it didn't
I'm trying to use Reflection.Emit in C# to emit a using (x) { ...
I tried using the Microsoft ReportingControls but found them overly cumbersome, with too little
I tried using "cap rollback" but I get the following error: $ cap rollback
I tried using PHPDoc for the first time today and quickly ran into a
I tried using both ReadProcessMemory() and WriteProcessMemory() in my application,but in both cases I
I tried using $(date) in my bash shell script, however, I want the date
I tried using aegis -change_attributes to change the brief_description of my current change set

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.