Search code examples
androidconstructorprivatepublicandroid-annotations

android annotations MyTask_(Context) has private access in MyTask_


I`m using @EBean MyTask class with androidannotations.I want to create new instance of the generated class like this

myTask = new MyTask_(this);

and it gives me error:

Error:(65, 28) error: MyTask_(Context) has private access in MyTask_

Generated class has a private method:

private MyTask_(Context context) {
    context_ = context;
    init_();
}

The question is that what to do in order to android annotations can declare constructor public? or how can i access to private constructor?


Solution

  • Generally you should not instantiate the bean yourself, but inject it in a field via the @Bean annotation:

    @Bean
    MyTask injected;
    

    However, if you really have to, you can use the generated getInstance_() method:

    MyTask task = MyTask_.getInstance_(context);