Objects after inject is null












0















I am trying to inject objects that are singletons to 2 activity.

My problem is, Milk and Coffee object after @Inject are null into Activity.
In my opinion I miss something.

Please help me and tell me what is missing in the code



AppComponent:



@Singleton
@Component(modules = {CoffeeModule.class, MilkModule.class})
public interface AppComponent {

@Component.Builder
interface Builder {
@BindsInstance
Builder appModule(MyMvpApp myMvpApp);

AppComponent build();

}
void inject(MyMvpApp app);
}


CoffeeModule:



@Module
public class CoffeeModule {

@Provides
@Singleton
Coffee getCoffee(){
return new Coffee();
}

}


MilkModule:



@Module
public class MilkModule {

@Provides
@Singleton
Milk getMilk(){
return new Milk();
}

}


My class App:



public class MyMvpApp extends Application{

@Override
public void onCreate() {
super.onCreate();
initDagger();
}

private void initDagger() {
AppComponent appComponent = DaggerAppComponent.builder()
.appModule(this)
.build();
appComponent.inject(this);
}

}


And my Activity on which these objects are null:



public class LoginActivity extends AppCompatActivity {

@Inject
Milk milk;

@Inject
Coffee coffee;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
Log.i("tag", "" + milk + coffee);
}
}









share|improve this question


















  • 1





    shouldn't be there a ...inject(this) statement in the LoginActivity ?

    – ashishdhiman2007
    Dec 29 '18 at 10:52











  • how to "...inject(this)" into activity ?

    – purcha
    Dec 29 '18 at 11:03
















0















I am trying to inject objects that are singletons to 2 activity.

My problem is, Milk and Coffee object after @Inject are null into Activity.
In my opinion I miss something.

Please help me and tell me what is missing in the code



AppComponent:



@Singleton
@Component(modules = {CoffeeModule.class, MilkModule.class})
public interface AppComponent {

@Component.Builder
interface Builder {
@BindsInstance
Builder appModule(MyMvpApp myMvpApp);

AppComponent build();

}
void inject(MyMvpApp app);
}


CoffeeModule:



@Module
public class CoffeeModule {

@Provides
@Singleton
Coffee getCoffee(){
return new Coffee();
}

}


MilkModule:



@Module
public class MilkModule {

@Provides
@Singleton
Milk getMilk(){
return new Milk();
}

}


My class App:



public class MyMvpApp extends Application{

@Override
public void onCreate() {
super.onCreate();
initDagger();
}

private void initDagger() {
AppComponent appComponent = DaggerAppComponent.builder()
.appModule(this)
.build();
appComponent.inject(this);
}

}


And my Activity on which these objects are null:



public class LoginActivity extends AppCompatActivity {

@Inject
Milk milk;

@Inject
Coffee coffee;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
Log.i("tag", "" + milk + coffee);
}
}









share|improve this question


















  • 1





    shouldn't be there a ...inject(this) statement in the LoginActivity ?

    – ashishdhiman2007
    Dec 29 '18 at 10:52











  • how to "...inject(this)" into activity ?

    – purcha
    Dec 29 '18 at 11:03














0












0








0








I am trying to inject objects that are singletons to 2 activity.

My problem is, Milk and Coffee object after @Inject are null into Activity.
In my opinion I miss something.

Please help me and tell me what is missing in the code



AppComponent:



@Singleton
@Component(modules = {CoffeeModule.class, MilkModule.class})
public interface AppComponent {

@Component.Builder
interface Builder {
@BindsInstance
Builder appModule(MyMvpApp myMvpApp);

AppComponent build();

}
void inject(MyMvpApp app);
}


CoffeeModule:



@Module
public class CoffeeModule {

@Provides
@Singleton
Coffee getCoffee(){
return new Coffee();
}

}


MilkModule:



@Module
public class MilkModule {

@Provides
@Singleton
Milk getMilk(){
return new Milk();
}

}


My class App:



public class MyMvpApp extends Application{

@Override
public void onCreate() {
super.onCreate();
initDagger();
}

private void initDagger() {
AppComponent appComponent = DaggerAppComponent.builder()
.appModule(this)
.build();
appComponent.inject(this);
}

}


And my Activity on which these objects are null:



public class LoginActivity extends AppCompatActivity {

@Inject
Milk milk;

@Inject
Coffee coffee;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
Log.i("tag", "" + milk + coffee);
}
}









share|improve this question














I am trying to inject objects that are singletons to 2 activity.

My problem is, Milk and Coffee object after @Inject are null into Activity.
In my opinion I miss something.

Please help me and tell me what is missing in the code



AppComponent:



@Singleton
@Component(modules = {CoffeeModule.class, MilkModule.class})
public interface AppComponent {

@Component.Builder
interface Builder {
@BindsInstance
Builder appModule(MyMvpApp myMvpApp);

AppComponent build();

}
void inject(MyMvpApp app);
}


CoffeeModule:



@Module
public class CoffeeModule {

@Provides
@Singleton
Coffee getCoffee(){
return new Coffee();
}

}


MilkModule:



@Module
public class MilkModule {

@Provides
@Singleton
Milk getMilk(){
return new Milk();
}

}


My class App:



public class MyMvpApp extends Application{

@Override
public void onCreate() {
super.onCreate();
initDagger();
}

private void initDagger() {
AppComponent appComponent = DaggerAppComponent.builder()
.appModule(this)
.build();
appComponent.inject(this);
}

}


And my Activity on which these objects are null:



public class LoginActivity extends AppCompatActivity {

@Inject
Milk milk;

@Inject
Coffee coffee;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
Log.i("tag", "" + milk + coffee);
}
}






java android dagger-2






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Dec 29 '18 at 10:46









purchapurcha

707




707








  • 1





    shouldn't be there a ...inject(this) statement in the LoginActivity ?

    – ashishdhiman2007
    Dec 29 '18 at 10:52











  • how to "...inject(this)" into activity ?

    – purcha
    Dec 29 '18 at 11:03














  • 1





    shouldn't be there a ...inject(this) statement in the LoginActivity ?

    – ashishdhiman2007
    Dec 29 '18 at 10:52











  • how to "...inject(this)" into activity ?

    – purcha
    Dec 29 '18 at 11:03








1




1





shouldn't be there a ...inject(this) statement in the LoginActivity ?

– ashishdhiman2007
Dec 29 '18 at 10:52





shouldn't be there a ...inject(this) statement in the LoginActivity ?

– ashishdhiman2007
Dec 29 '18 at 10:52













how to "...inject(this)" into activity ?

– purcha
Dec 29 '18 at 11:03





how to "...inject(this)" into activity ?

– purcha
Dec 29 '18 at 11:03












2 Answers
2






active

oldest

votes


















1














@Singleton
@Component(modules = {CoffeeModule.class, MilkModule.class})
public interface AppComponent {

void inject(LoginActivity app);

@Component.Builder
interface Builder {
@BindsInstance
Builder appModule(MyMvpApp myMvpApp);

AppComponent build();
}
}



public class LoginActivity extends AppCompatActivity {
@Inject
Milk milk;

@Inject
Coffee coffee;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
DaggerAppComponent.builder().appModule((MyMvpApp) getApplicationContext()).build().inject(this);
Log.i("tag", "" + milk + coffee);
}
}


public class MyMvpApp extends Application {

@Override
public void onCreate() {
super.onCreate();
initDagger();
}

private void initDagger() {
AppComponent appComponent = DaggerAppComponent.builder()
.appModule(this)
.build();
}
}





share|improve this answer
























  • and I need in every Activity an fragment create DaggerAppComponent.builder ? I saw sometimes AndroidInjection.inject(this), it is this same ?

    – purcha
    Dec 29 '18 at 11:34











  • may be then you will need to follow a different approach using "dagger.android" package.

    – ashishdhiman2007
    Dec 29 '18 at 11:56



















1














You have to add two more lines inside your AppComponent class.



void inject(MyMvpApp app);

//you need to provide milk and coffee here
Milk getMilk();
Coffee getCoffee();


Edit 1 : one more thing you need to inject your activity too in the app component.



void inject(LoginActivity loginActivity);


and call the initDagger method in the activity in the same way you are doing in your Application class.



Edit 2 :If you dont want to repeat the whole thing,then create one method in your application class like this:



 private AppComponent appComponent ;

public AppComponent getAppComponent(){
if (appComponent == null) {
appComponent = DaggerAppComponent.builder()
.appModule(this)
.build();
}
return appComponent;
}

public void initDagger(){
appComponent.inject(this);
}


Inside onCreate of Application class, call these methods.



getAppComponent();
initDagger();


Inside your activity, you can do like this rather than initializing the whole module again and again.



public void initDagger(){
getApplication().getAppCompoment().inject(this);
}





share|improve this answer


























  • they are still null after added this 2 line

    – purcha
    Dec 29 '18 at 11:23











  • ((MyMvpApp)getApplication()).getAppCompoment().inject(this); // to get the result of getAppComponent as Application class has no "getAppCompoment()" method.

    – ashishdhiman2007
    Dec 31 '18 at 5:13











  • I already mentioned in the edit 2 that you need to write the getAppComponent() in your application class ie class name which is extending Application class

    – Ajay Chauhan
    Dec 31 '18 at 6:26













  • Yes, thats why it is necessary to specify the class name(used in casting) having the method "getAppCompoment()", because I see getApplication() returns android Application instance not the custom one that extends Application and have method: "getAppCompoment()"

    – ashishdhiman2007
    Dec 31 '18 at 12:39













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53968820%2fobjects-after-inject-is-null%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














@Singleton
@Component(modules = {CoffeeModule.class, MilkModule.class})
public interface AppComponent {

void inject(LoginActivity app);

@Component.Builder
interface Builder {
@BindsInstance
Builder appModule(MyMvpApp myMvpApp);

AppComponent build();
}
}



public class LoginActivity extends AppCompatActivity {
@Inject
Milk milk;

@Inject
Coffee coffee;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
DaggerAppComponent.builder().appModule((MyMvpApp) getApplicationContext()).build().inject(this);
Log.i("tag", "" + milk + coffee);
}
}


public class MyMvpApp extends Application {

@Override
public void onCreate() {
super.onCreate();
initDagger();
}

private void initDagger() {
AppComponent appComponent = DaggerAppComponent.builder()
.appModule(this)
.build();
}
}





share|improve this answer
























  • and I need in every Activity an fragment create DaggerAppComponent.builder ? I saw sometimes AndroidInjection.inject(this), it is this same ?

    – purcha
    Dec 29 '18 at 11:34











  • may be then you will need to follow a different approach using "dagger.android" package.

    – ashishdhiman2007
    Dec 29 '18 at 11:56
















1














@Singleton
@Component(modules = {CoffeeModule.class, MilkModule.class})
public interface AppComponent {

void inject(LoginActivity app);

@Component.Builder
interface Builder {
@BindsInstance
Builder appModule(MyMvpApp myMvpApp);

AppComponent build();
}
}



public class LoginActivity extends AppCompatActivity {
@Inject
Milk milk;

@Inject
Coffee coffee;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
DaggerAppComponent.builder().appModule((MyMvpApp) getApplicationContext()).build().inject(this);
Log.i("tag", "" + milk + coffee);
}
}


public class MyMvpApp extends Application {

@Override
public void onCreate() {
super.onCreate();
initDagger();
}

private void initDagger() {
AppComponent appComponent = DaggerAppComponent.builder()
.appModule(this)
.build();
}
}





share|improve this answer
























  • and I need in every Activity an fragment create DaggerAppComponent.builder ? I saw sometimes AndroidInjection.inject(this), it is this same ?

    – purcha
    Dec 29 '18 at 11:34











  • may be then you will need to follow a different approach using "dagger.android" package.

    – ashishdhiman2007
    Dec 29 '18 at 11:56














1












1








1







@Singleton
@Component(modules = {CoffeeModule.class, MilkModule.class})
public interface AppComponent {

void inject(LoginActivity app);

@Component.Builder
interface Builder {
@BindsInstance
Builder appModule(MyMvpApp myMvpApp);

AppComponent build();
}
}



public class LoginActivity extends AppCompatActivity {
@Inject
Milk milk;

@Inject
Coffee coffee;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
DaggerAppComponent.builder().appModule((MyMvpApp) getApplicationContext()).build().inject(this);
Log.i("tag", "" + milk + coffee);
}
}


public class MyMvpApp extends Application {

@Override
public void onCreate() {
super.onCreate();
initDagger();
}

private void initDagger() {
AppComponent appComponent = DaggerAppComponent.builder()
.appModule(this)
.build();
}
}





share|improve this answer













@Singleton
@Component(modules = {CoffeeModule.class, MilkModule.class})
public interface AppComponent {

void inject(LoginActivity app);

@Component.Builder
interface Builder {
@BindsInstance
Builder appModule(MyMvpApp myMvpApp);

AppComponent build();
}
}



public class LoginActivity extends AppCompatActivity {
@Inject
Milk milk;

@Inject
Coffee coffee;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
DaggerAppComponent.builder().appModule((MyMvpApp) getApplicationContext()).build().inject(this);
Log.i("tag", "" + milk + coffee);
}
}


public class MyMvpApp extends Application {

@Override
public void onCreate() {
super.onCreate();
initDagger();
}

private void initDagger() {
AppComponent appComponent = DaggerAppComponent.builder()
.appModule(this)
.build();
}
}






share|improve this answer












share|improve this answer



share|improve this answer










answered Dec 29 '18 at 11:30









ashishdhiman2007ashishdhiman2007

3371416




3371416













  • and I need in every Activity an fragment create DaggerAppComponent.builder ? I saw sometimes AndroidInjection.inject(this), it is this same ?

    – purcha
    Dec 29 '18 at 11:34











  • may be then you will need to follow a different approach using "dagger.android" package.

    – ashishdhiman2007
    Dec 29 '18 at 11:56



















  • and I need in every Activity an fragment create DaggerAppComponent.builder ? I saw sometimes AndroidInjection.inject(this), it is this same ?

    – purcha
    Dec 29 '18 at 11:34











  • may be then you will need to follow a different approach using "dagger.android" package.

    – ashishdhiman2007
    Dec 29 '18 at 11:56

















and I need in every Activity an fragment create DaggerAppComponent.builder ? I saw sometimes AndroidInjection.inject(this), it is this same ?

– purcha
Dec 29 '18 at 11:34





and I need in every Activity an fragment create DaggerAppComponent.builder ? I saw sometimes AndroidInjection.inject(this), it is this same ?

– purcha
Dec 29 '18 at 11:34













may be then you will need to follow a different approach using "dagger.android" package.

– ashishdhiman2007
Dec 29 '18 at 11:56





may be then you will need to follow a different approach using "dagger.android" package.

– ashishdhiman2007
Dec 29 '18 at 11:56













1














You have to add two more lines inside your AppComponent class.



void inject(MyMvpApp app);

//you need to provide milk and coffee here
Milk getMilk();
Coffee getCoffee();


Edit 1 : one more thing you need to inject your activity too in the app component.



void inject(LoginActivity loginActivity);


and call the initDagger method in the activity in the same way you are doing in your Application class.



Edit 2 :If you dont want to repeat the whole thing,then create one method in your application class like this:



 private AppComponent appComponent ;

public AppComponent getAppComponent(){
if (appComponent == null) {
appComponent = DaggerAppComponent.builder()
.appModule(this)
.build();
}
return appComponent;
}

public void initDagger(){
appComponent.inject(this);
}


Inside onCreate of Application class, call these methods.



getAppComponent();
initDagger();


Inside your activity, you can do like this rather than initializing the whole module again and again.



public void initDagger(){
getApplication().getAppCompoment().inject(this);
}





share|improve this answer


























  • they are still null after added this 2 line

    – purcha
    Dec 29 '18 at 11:23











  • ((MyMvpApp)getApplication()).getAppCompoment().inject(this); // to get the result of getAppComponent as Application class has no "getAppCompoment()" method.

    – ashishdhiman2007
    Dec 31 '18 at 5:13











  • I already mentioned in the edit 2 that you need to write the getAppComponent() in your application class ie class name which is extending Application class

    – Ajay Chauhan
    Dec 31 '18 at 6:26













  • Yes, thats why it is necessary to specify the class name(used in casting) having the method "getAppCompoment()", because I see getApplication() returns android Application instance not the custom one that extends Application and have method: "getAppCompoment()"

    – ashishdhiman2007
    Dec 31 '18 at 12:39


















1














You have to add two more lines inside your AppComponent class.



void inject(MyMvpApp app);

//you need to provide milk and coffee here
Milk getMilk();
Coffee getCoffee();


Edit 1 : one more thing you need to inject your activity too in the app component.



void inject(LoginActivity loginActivity);


and call the initDagger method in the activity in the same way you are doing in your Application class.



Edit 2 :If you dont want to repeat the whole thing,then create one method in your application class like this:



 private AppComponent appComponent ;

public AppComponent getAppComponent(){
if (appComponent == null) {
appComponent = DaggerAppComponent.builder()
.appModule(this)
.build();
}
return appComponent;
}

public void initDagger(){
appComponent.inject(this);
}


Inside onCreate of Application class, call these methods.



getAppComponent();
initDagger();


Inside your activity, you can do like this rather than initializing the whole module again and again.



public void initDagger(){
getApplication().getAppCompoment().inject(this);
}





share|improve this answer


























  • they are still null after added this 2 line

    – purcha
    Dec 29 '18 at 11:23











  • ((MyMvpApp)getApplication()).getAppCompoment().inject(this); // to get the result of getAppComponent as Application class has no "getAppCompoment()" method.

    – ashishdhiman2007
    Dec 31 '18 at 5:13











  • I already mentioned in the edit 2 that you need to write the getAppComponent() in your application class ie class name which is extending Application class

    – Ajay Chauhan
    Dec 31 '18 at 6:26













  • Yes, thats why it is necessary to specify the class name(used in casting) having the method "getAppCompoment()", because I see getApplication() returns android Application instance not the custom one that extends Application and have method: "getAppCompoment()"

    – ashishdhiman2007
    Dec 31 '18 at 12:39
















1












1








1







You have to add two more lines inside your AppComponent class.



void inject(MyMvpApp app);

//you need to provide milk and coffee here
Milk getMilk();
Coffee getCoffee();


Edit 1 : one more thing you need to inject your activity too in the app component.



void inject(LoginActivity loginActivity);


and call the initDagger method in the activity in the same way you are doing in your Application class.



Edit 2 :If you dont want to repeat the whole thing,then create one method in your application class like this:



 private AppComponent appComponent ;

public AppComponent getAppComponent(){
if (appComponent == null) {
appComponent = DaggerAppComponent.builder()
.appModule(this)
.build();
}
return appComponent;
}

public void initDagger(){
appComponent.inject(this);
}


Inside onCreate of Application class, call these methods.



getAppComponent();
initDagger();


Inside your activity, you can do like this rather than initializing the whole module again and again.



public void initDagger(){
getApplication().getAppCompoment().inject(this);
}





share|improve this answer















You have to add two more lines inside your AppComponent class.



void inject(MyMvpApp app);

//you need to provide milk and coffee here
Milk getMilk();
Coffee getCoffee();


Edit 1 : one more thing you need to inject your activity too in the app component.



void inject(LoginActivity loginActivity);


and call the initDagger method in the activity in the same way you are doing in your Application class.



Edit 2 :If you dont want to repeat the whole thing,then create one method in your application class like this:



 private AppComponent appComponent ;

public AppComponent getAppComponent(){
if (appComponent == null) {
appComponent = DaggerAppComponent.builder()
.appModule(this)
.build();
}
return appComponent;
}

public void initDagger(){
appComponent.inject(this);
}


Inside onCreate of Application class, call these methods.



getAppComponent();
initDagger();


Inside your activity, you can do like this rather than initializing the whole module again and again.



public void initDagger(){
getApplication().getAppCompoment().inject(this);
}






share|improve this answer














share|improve this answer



share|improve this answer








edited Dec 29 '18 at 13:42

























answered Dec 29 '18 at 11:19









Ajay ChauhanAjay Chauhan

217215




217215













  • they are still null after added this 2 line

    – purcha
    Dec 29 '18 at 11:23











  • ((MyMvpApp)getApplication()).getAppCompoment().inject(this); // to get the result of getAppComponent as Application class has no "getAppCompoment()" method.

    – ashishdhiman2007
    Dec 31 '18 at 5:13











  • I already mentioned in the edit 2 that you need to write the getAppComponent() in your application class ie class name which is extending Application class

    – Ajay Chauhan
    Dec 31 '18 at 6:26













  • Yes, thats why it is necessary to specify the class name(used in casting) having the method "getAppCompoment()", because I see getApplication() returns android Application instance not the custom one that extends Application and have method: "getAppCompoment()"

    – ashishdhiman2007
    Dec 31 '18 at 12:39





















  • they are still null after added this 2 line

    – purcha
    Dec 29 '18 at 11:23











  • ((MyMvpApp)getApplication()).getAppCompoment().inject(this); // to get the result of getAppComponent as Application class has no "getAppCompoment()" method.

    – ashishdhiman2007
    Dec 31 '18 at 5:13











  • I already mentioned in the edit 2 that you need to write the getAppComponent() in your application class ie class name which is extending Application class

    – Ajay Chauhan
    Dec 31 '18 at 6:26













  • Yes, thats why it is necessary to specify the class name(used in casting) having the method "getAppCompoment()", because I see getApplication() returns android Application instance not the custom one that extends Application and have method: "getAppCompoment()"

    – ashishdhiman2007
    Dec 31 '18 at 12:39



















they are still null after added this 2 line

– purcha
Dec 29 '18 at 11:23





they are still null after added this 2 line

– purcha
Dec 29 '18 at 11:23













((MyMvpApp)getApplication()).getAppCompoment().inject(this); // to get the result of getAppComponent as Application class has no "getAppCompoment()" method.

– ashishdhiman2007
Dec 31 '18 at 5:13





((MyMvpApp)getApplication()).getAppCompoment().inject(this); // to get the result of getAppComponent as Application class has no "getAppCompoment()" method.

– ashishdhiman2007
Dec 31 '18 at 5:13













I already mentioned in the edit 2 that you need to write the getAppComponent() in your application class ie class name which is extending Application class

– Ajay Chauhan
Dec 31 '18 at 6:26







I already mentioned in the edit 2 that you need to write the getAppComponent() in your application class ie class name which is extending Application class

– Ajay Chauhan
Dec 31 '18 at 6:26















Yes, thats why it is necessary to specify the class name(used in casting) having the method "getAppCompoment()", because I see getApplication() returns android Application instance not the custom one that extends Application and have method: "getAppCompoment()"

– ashishdhiman2007
Dec 31 '18 at 12:39







Yes, thats why it is necessary to specify the class name(used in casting) having the method "getAppCompoment()", because I see getApplication() returns android Application instance not the custom one that extends Application and have method: "getAppCompoment()"

– ashishdhiman2007
Dec 31 '18 at 12:39




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53968820%2fobjects-after-inject-is-null%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas