Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dollar ($) sign after activity class name in Android logs (non-anonymous inner class) [duplicate]

I am going through some crash logs for my app and the stack trace shows something like :

at MyActivity.formatDouble(MyActivity.java:182)
at MyActivity.access$47(MyActivity.java:196)    
at MyActivity$28.onCameraChange(MyActivity.java:167)

"MyActivity" is an activity and hence not an anonymous inner class. I can't be sure of the dollar sign on line#3 (and the one in line#2 also)

like image 734
BadCode Avatar asked Mar 22 '23 05:03

BadCode


1 Answers

I suspect that line 167 is within an anonymous class within MyActivity, and that access$47 is simply a trampoline method to allow onCameraChange to call a private method within MyActivity. (The JVM wouldn't allow that, so the Java compiler creates a method to allow it.)

You can see this easily with a simple Java class not even on Android:

public class Test {

    private static void privateMethod() {
        throw new RuntimeException();
    }

    public static void main(String[] args) throws Exception {
        Runnable runnable = new Runnable() {
            @Override public void run() {
                privateMethod();
            }
        };
        runnable.run();
    }
}

This gives a stack trace similar to the one you've shown:

Exception in thread "main" java.lang.RuntimeException
        at Test.privateMethod(Test.java:4)
        at Test.access$000(Test.java:1)
        at Test$1.run(Test.java:10)
        at Test.main(Test.java:13)

The Test$1.run is within an anonymous inner class within main, and the access$000 method is providing access to privateMethod.

like image 72
Jon Skeet Avatar answered Apr 14 '23 16:04

Jon Skeet