1

Here I am going to print all the methods that are inside the class using reflection, so in a normal JAVA program it is going to print. But in Android layout it is displaying only one method:

public static void main() throws Exception{
    Log.i("Ramu","I am here displayM ");
    Class o =Class.forName("android.view.AbsSavedState");
    Method M[]=o.getMethods();
    for( i=0;i<M.length;i++)
        methodname = M[i].getName();
    Listview.your_array_list.add(methodname);
    Listview.your_array_list.add(methodname);
    Log.i("Ramu","methode name "+ M[i].getName());
    //System.out.println(M[i].getName());
}
1
  • Are you aware that you will only get the last methode stored in M with that for loop ? for( i=0;i<M.length;i++) methodname = M[i].getName(); Commented Apr 2, 2014 at 8:09

3 Answers 3

1

Your loop ended the very next line of declaration and also u were printing only method name at at final index value after the loop completion. Try using braces, that will solve the problem. Check following code

public static void main() throws Exception{
    Log.i("Ramu","I am here displayM ");
    Class o =Class.forName("android.view.AbsSavedState");
    Method M[]=o.getMethods();
    for( i=0;i<M.length;i++){
        methodname = M[i].getName();
    Listview.your_array_list.add(methodname);
    Listview.your_array_list.add(methodname);
    Log.i("Ramu","methode name "+ M[i].getName());
}

    //System.out.println(M[i].getName());
}
Sign up to request clarification or add additional context in comments.

1 Comment

if u found my answer helpful then please care to accept it!!
0

u forgot { } of for loop dude just keep it in { } and then try

for( i=0;i<M.length;i++)
{

        methodname = M[i].getName();
    Listview.your_array_list.add(methodname);
     Log.i("Ramu","methode name "+ M[i].getName());
}

Comments

0

You've forgot to put the brackets, that's you don't get expected output:

Class o = Class.forName("android.view.AbsSavedState");
Method M[] = o.getMethods();
for (int i = 0; i < M.length; i++) {
    methodname = M[i].getName();
    Listview.your_array_list.add(methodname);
    Log.i("Ramu", "method name " + methodname);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.