Good day to all!

Found an interesting tool for tracking errors like ООМ - LeakCanary . There are a couple of articles in Russian here and here . The problem is that I cannot implement it in my project (I specifically created the project).

activation code that runs from the main activation

 public class ac2 extends AppCompatActivity { Cat schrodingerCat; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.ssss); Box box = new Box(); schrodingerCat = new Cat(); box.hiddenCat = schrodingerCat; Docker.container = box; } @Override public void onDestroy() { super.onDestroy(); RefWatcher refWatcher = ExampleApplication.getRefWatcher(this); refWatcher.watch(this); refWatcher.watch(schrodingerCat); } 

class code inheriting application

 public class ExampleApplication extends Application { private RefWatcher refWatcher; public static RefWatcher getRefWatcher(Context context) { ExampleApplication application = (ExampleApplication) context.getApplicationContext(); return application.refWatcher; } @Override public void onCreate() { super.onCreate(); refWatcher = LeakCanary.install(this); }} 

and three classes that help create ООМ

 public class Cat { } public class Box { Cat hiddenCat; } public class Docker { static Box container; } 

the application crashes when I close ac2 activi (I return to the main point). Apparently I do not understand something, who faced the problem, please help. I do as they say here

Error - type casting. falls in a row

 ExampleApplication application = (ExampleApplication) context.getApplicationContext(); 

E / AndroidRuntime: Caused by: java.lang.ClassCastException: canaryleak.ac2 cannot be cast to canaryleak.ExampleApplication

E / AndroidRuntime: at canaryleak.ExampleApplication.getRefWatcher (ExampleApplication.java:17)

    1 answer 1

    You did not register your Application in the manifest. Add the name parameter with the name of your Application to the application section.

     <application ... android:name=".ExampleApplication "> ... </application> 
    • Thank! Children's mistake ( - Pavel K