Android: Application class not recognized in Dagger2 Component












0















It seems like I cant find the MyApplication class from my ApplicationComponent:



enter image description here



And this error output:




error: cannot find symbol class MyApplication




Here is all the related classes:



ApplicationComponent:



@ApplicationScope
@Component(modules = {ApplicationContextModule.class,
SharedPreferencesModule.class,
KeyStoreModule.class,
SharedPreferenceHelperModule.class,
StartModule.class,
AndroidInjectionModule.class,
BindModule.class,
AndroidSupportInjectionModule.class})
public interface ApplicationComponent {

void inject(MyApplication myApplication);

@Component.Builder
interface Builder {
@BindsInstance
Builder application(MyApplication myApplication); //CANT FIND MYAPPLICATION
ApplicationComponent build();
}

@ApplicationContext
Context getApplicationContext();

SharedPreferences getSharedPreferences();

KeyStoreServiceInterface getKeyStoreService();

SharedPreferencesHelper getSharedPreferencesHelper();

StartViewModelFactory getStartViewModelFactory();

}


MyApplication class:



public class MyApplication extends MultiDexApplication implements HasActivityInjector {

private ApplicationComponent applicationComponent;

@Inject
DispatchingAndroidInjector<Activity> dispatchingActivityInjector;

@Override
public void onCreate() {
super.onCreate();
applicationComponent = DaggerApplicationComponent.builder()
.applicationContextModule(new ApplicationContextModule(this))
.build();
DaggerApplicationComponent
.builder()
.build()
.inject(this); //ERROR HERE. Complains that there is no inject method, offers creation of one in ApplicationComponent, but already exists one.
}

@Override
public AndroidInjector<Activity> activityInjector() {
return dispatchingActivityInjector;
}

public ApplicationComponent getApplicationComponent() {
return applicationComponent;
}
}


And here is my manifest:



<application
android:name="MyApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:replace="android:appComponentFactory"
android:appComponentFactory="whateverString">
<activity android:name="start.StartActivity" ></activity>
</application>


Why does it not recognize the class?










share|improve this question























  • android:name="MyApplication" should be android:name=".MyApplication"

    – Pavneet_Singh
    Nov 21 '18 at 16:22











  • @Pavneet_Singh it gives me error unresolved class and suggest class creation. I am guessing the placement of MyApplication in the folders gives me this. Is there a way to find the path?

    – Carlton
    Nov 21 '18 at 16:24











  • use command+shit+f to find your class

    – Pavneet_Singh
    Nov 21 '18 at 16:27











  • Thanks. MyApplication is in the root folder. This should work by adding the dot, but my component still cant find it. Any more suggestions? @Pavneet_Singh

    – Carlton
    Nov 21 '18 at 16:56






  • 1





    @Pavneet_Singh It was 100% a package name issue. Moved MyApplication to a new folder and added foldername before .MyApplication and no problems anymore. Thanks for the help. Please, if you would like, post your latest comment+(the dot comment) as an answer so I can upvote&accept for if anyone else might have use of it. Thanks

    – Carlton
    Nov 21 '18 at 17:35
















0















It seems like I cant find the MyApplication class from my ApplicationComponent:



enter image description here



And this error output:




error: cannot find symbol class MyApplication




Here is all the related classes:



ApplicationComponent:



@ApplicationScope
@Component(modules = {ApplicationContextModule.class,
SharedPreferencesModule.class,
KeyStoreModule.class,
SharedPreferenceHelperModule.class,
StartModule.class,
AndroidInjectionModule.class,
BindModule.class,
AndroidSupportInjectionModule.class})
public interface ApplicationComponent {

void inject(MyApplication myApplication);

@Component.Builder
interface Builder {
@BindsInstance
Builder application(MyApplication myApplication); //CANT FIND MYAPPLICATION
ApplicationComponent build();
}

@ApplicationContext
Context getApplicationContext();

SharedPreferences getSharedPreferences();

KeyStoreServiceInterface getKeyStoreService();

SharedPreferencesHelper getSharedPreferencesHelper();

StartViewModelFactory getStartViewModelFactory();

}


MyApplication class:



public class MyApplication extends MultiDexApplication implements HasActivityInjector {

private ApplicationComponent applicationComponent;

@Inject
DispatchingAndroidInjector<Activity> dispatchingActivityInjector;

@Override
public void onCreate() {
super.onCreate();
applicationComponent = DaggerApplicationComponent.builder()
.applicationContextModule(new ApplicationContextModule(this))
.build();
DaggerApplicationComponent
.builder()
.build()
.inject(this); //ERROR HERE. Complains that there is no inject method, offers creation of one in ApplicationComponent, but already exists one.
}

@Override
public AndroidInjector<Activity> activityInjector() {
return dispatchingActivityInjector;
}

public ApplicationComponent getApplicationComponent() {
return applicationComponent;
}
}


And here is my manifest:



<application
android:name="MyApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:replace="android:appComponentFactory"
android:appComponentFactory="whateverString">
<activity android:name="start.StartActivity" ></activity>
</application>


Why does it not recognize the class?










share|improve this question























  • android:name="MyApplication" should be android:name=".MyApplication"

    – Pavneet_Singh
    Nov 21 '18 at 16:22











  • @Pavneet_Singh it gives me error unresolved class and suggest class creation. I am guessing the placement of MyApplication in the folders gives me this. Is there a way to find the path?

    – Carlton
    Nov 21 '18 at 16:24











  • use command+shit+f to find your class

    – Pavneet_Singh
    Nov 21 '18 at 16:27











  • Thanks. MyApplication is in the root folder. This should work by adding the dot, but my component still cant find it. Any more suggestions? @Pavneet_Singh

    – Carlton
    Nov 21 '18 at 16:56






  • 1





    @Pavneet_Singh It was 100% a package name issue. Moved MyApplication to a new folder and added foldername before .MyApplication and no problems anymore. Thanks for the help. Please, if you would like, post your latest comment+(the dot comment) as an answer so I can upvote&accept for if anyone else might have use of it. Thanks

    – Carlton
    Nov 21 '18 at 17:35














0












0








0








It seems like I cant find the MyApplication class from my ApplicationComponent:



enter image description here



And this error output:




error: cannot find symbol class MyApplication




Here is all the related classes:



ApplicationComponent:



@ApplicationScope
@Component(modules = {ApplicationContextModule.class,
SharedPreferencesModule.class,
KeyStoreModule.class,
SharedPreferenceHelperModule.class,
StartModule.class,
AndroidInjectionModule.class,
BindModule.class,
AndroidSupportInjectionModule.class})
public interface ApplicationComponent {

void inject(MyApplication myApplication);

@Component.Builder
interface Builder {
@BindsInstance
Builder application(MyApplication myApplication); //CANT FIND MYAPPLICATION
ApplicationComponent build();
}

@ApplicationContext
Context getApplicationContext();

SharedPreferences getSharedPreferences();

KeyStoreServiceInterface getKeyStoreService();

SharedPreferencesHelper getSharedPreferencesHelper();

StartViewModelFactory getStartViewModelFactory();

}


MyApplication class:



public class MyApplication extends MultiDexApplication implements HasActivityInjector {

private ApplicationComponent applicationComponent;

@Inject
DispatchingAndroidInjector<Activity> dispatchingActivityInjector;

@Override
public void onCreate() {
super.onCreate();
applicationComponent = DaggerApplicationComponent.builder()
.applicationContextModule(new ApplicationContextModule(this))
.build();
DaggerApplicationComponent
.builder()
.build()
.inject(this); //ERROR HERE. Complains that there is no inject method, offers creation of one in ApplicationComponent, but already exists one.
}

@Override
public AndroidInjector<Activity> activityInjector() {
return dispatchingActivityInjector;
}

public ApplicationComponent getApplicationComponent() {
return applicationComponent;
}
}


And here is my manifest:



<application
android:name="MyApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:replace="android:appComponentFactory"
android:appComponentFactory="whateverString">
<activity android:name="start.StartActivity" ></activity>
</application>


Why does it not recognize the class?










share|improve this question














It seems like I cant find the MyApplication class from my ApplicationComponent:



enter image description here



And this error output:




error: cannot find symbol class MyApplication




Here is all the related classes:



ApplicationComponent:



@ApplicationScope
@Component(modules = {ApplicationContextModule.class,
SharedPreferencesModule.class,
KeyStoreModule.class,
SharedPreferenceHelperModule.class,
StartModule.class,
AndroidInjectionModule.class,
BindModule.class,
AndroidSupportInjectionModule.class})
public interface ApplicationComponent {

void inject(MyApplication myApplication);

@Component.Builder
interface Builder {
@BindsInstance
Builder application(MyApplication myApplication); //CANT FIND MYAPPLICATION
ApplicationComponent build();
}

@ApplicationContext
Context getApplicationContext();

SharedPreferences getSharedPreferences();

KeyStoreServiceInterface getKeyStoreService();

SharedPreferencesHelper getSharedPreferencesHelper();

StartViewModelFactory getStartViewModelFactory();

}


MyApplication class:



public class MyApplication extends MultiDexApplication implements HasActivityInjector {

private ApplicationComponent applicationComponent;

@Inject
DispatchingAndroidInjector<Activity> dispatchingActivityInjector;

@Override
public void onCreate() {
super.onCreate();
applicationComponent = DaggerApplicationComponent.builder()
.applicationContextModule(new ApplicationContextModule(this))
.build();
DaggerApplicationComponent
.builder()
.build()
.inject(this); //ERROR HERE. Complains that there is no inject method, offers creation of one in ApplicationComponent, but already exists one.
}

@Override
public AndroidInjector<Activity> activityInjector() {
return dispatchingActivityInjector;
}

public ApplicationComponent getApplicationComponent() {
return applicationComponent;
}
}


And here is my manifest:



<application
android:name="MyApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:replace="android:appComponentFactory"
android:appComponentFactory="whateverString">
<activity android:name="start.StartActivity" ></activity>
</application>


Why does it not recognize the class?







android dagger-2 dagger






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 21 '18 at 16:20









CarltonCarlton

95321638




95321638













  • android:name="MyApplication" should be android:name=".MyApplication"

    – Pavneet_Singh
    Nov 21 '18 at 16:22











  • @Pavneet_Singh it gives me error unresolved class and suggest class creation. I am guessing the placement of MyApplication in the folders gives me this. Is there a way to find the path?

    – Carlton
    Nov 21 '18 at 16:24











  • use command+shit+f to find your class

    – Pavneet_Singh
    Nov 21 '18 at 16:27











  • Thanks. MyApplication is in the root folder. This should work by adding the dot, but my component still cant find it. Any more suggestions? @Pavneet_Singh

    – Carlton
    Nov 21 '18 at 16:56






  • 1





    @Pavneet_Singh It was 100% a package name issue. Moved MyApplication to a new folder and added foldername before .MyApplication and no problems anymore. Thanks for the help. Please, if you would like, post your latest comment+(the dot comment) as an answer so I can upvote&accept for if anyone else might have use of it. Thanks

    – Carlton
    Nov 21 '18 at 17:35



















  • android:name="MyApplication" should be android:name=".MyApplication"

    – Pavneet_Singh
    Nov 21 '18 at 16:22











  • @Pavneet_Singh it gives me error unresolved class and suggest class creation. I am guessing the placement of MyApplication in the folders gives me this. Is there a way to find the path?

    – Carlton
    Nov 21 '18 at 16:24











  • use command+shit+f to find your class

    – Pavneet_Singh
    Nov 21 '18 at 16:27











  • Thanks. MyApplication is in the root folder. This should work by adding the dot, but my component still cant find it. Any more suggestions? @Pavneet_Singh

    – Carlton
    Nov 21 '18 at 16:56






  • 1





    @Pavneet_Singh It was 100% a package name issue. Moved MyApplication to a new folder and added foldername before .MyApplication and no problems anymore. Thanks for the help. Please, if you would like, post your latest comment+(the dot comment) as an answer so I can upvote&accept for if anyone else might have use of it. Thanks

    – Carlton
    Nov 21 '18 at 17:35

















android:name="MyApplication" should be android:name=".MyApplication"

– Pavneet_Singh
Nov 21 '18 at 16:22





android:name="MyApplication" should be android:name=".MyApplication"

– Pavneet_Singh
Nov 21 '18 at 16:22













@Pavneet_Singh it gives me error unresolved class and suggest class creation. I am guessing the placement of MyApplication in the folders gives me this. Is there a way to find the path?

– Carlton
Nov 21 '18 at 16:24





@Pavneet_Singh it gives me error unresolved class and suggest class creation. I am guessing the placement of MyApplication in the folders gives me this. Is there a way to find the path?

– Carlton
Nov 21 '18 at 16:24













use command+shit+f to find your class

– Pavneet_Singh
Nov 21 '18 at 16:27





use command+shit+f to find your class

– Pavneet_Singh
Nov 21 '18 at 16:27













Thanks. MyApplication is in the root folder. This should work by adding the dot, but my component still cant find it. Any more suggestions? @Pavneet_Singh

– Carlton
Nov 21 '18 at 16:56





Thanks. MyApplication is in the root folder. This should work by adding the dot, but my component still cant find it. Any more suggestions? @Pavneet_Singh

– Carlton
Nov 21 '18 at 16:56




1




1





@Pavneet_Singh It was 100% a package name issue. Moved MyApplication to a new folder and added foldername before .MyApplication and no problems anymore. Thanks for the help. Please, if you would like, post your latest comment+(the dot comment) as an answer so I can upvote&accept for if anyone else might have use of it. Thanks

– Carlton
Nov 21 '18 at 17:35





@Pavneet_Singh It was 100% a package name issue. Moved MyApplication to a new folder and added foldername before .MyApplication and no problems anymore. Thanks for the help. Please, if you would like, post your latest comment+(the dot comment) as an answer so I can upvote&accept for if anyone else might have use of it. Thanks

– Carlton
Nov 21 '18 at 17:35












1 Answer
1






active

oldest

votes


















2














Apparently looks like a package name issue as component is unable to import it or use it so




  1. Move the Application class under the root package name (that you entered while creating app)


  2. Use .MyApplication to register you application class





android:name=".MyApplication"


or may also add any additional package name with application name






share|improve this answer
























  • Thanks again for the help

    – Carlton
    Nov 21 '18 at 17:46











  • I am glad that I could help, happy coding :)

    – Pavneet_Singh
    Nov 21 '18 at 17:47











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%2f53416365%2fandroid-application-class-not-recognized-in-dagger2-component%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














Apparently looks like a package name issue as component is unable to import it or use it so




  1. Move the Application class under the root package name (that you entered while creating app)


  2. Use .MyApplication to register you application class





android:name=".MyApplication"


or may also add any additional package name with application name






share|improve this answer
























  • Thanks again for the help

    – Carlton
    Nov 21 '18 at 17:46











  • I am glad that I could help, happy coding :)

    – Pavneet_Singh
    Nov 21 '18 at 17:47
















2














Apparently looks like a package name issue as component is unable to import it or use it so




  1. Move the Application class under the root package name (that you entered while creating app)


  2. Use .MyApplication to register you application class





android:name=".MyApplication"


or may also add any additional package name with application name






share|improve this answer
























  • Thanks again for the help

    – Carlton
    Nov 21 '18 at 17:46











  • I am glad that I could help, happy coding :)

    – Pavneet_Singh
    Nov 21 '18 at 17:47














2












2








2







Apparently looks like a package name issue as component is unable to import it or use it so




  1. Move the Application class under the root package name (that you entered while creating app)


  2. Use .MyApplication to register you application class





android:name=".MyApplication"


or may also add any additional package name with application name






share|improve this answer













Apparently looks like a package name issue as component is unable to import it or use it so




  1. Move the Application class under the root package name (that you entered while creating app)


  2. Use .MyApplication to register you application class





android:name=".MyApplication"


or may also add any additional package name with application name







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 21 '18 at 17:41









Pavneet_SinghPavneet_Singh

26.8k42644




26.8k42644













  • Thanks again for the help

    – Carlton
    Nov 21 '18 at 17:46











  • I am glad that I could help, happy coding :)

    – Pavneet_Singh
    Nov 21 '18 at 17:47



















  • Thanks again for the help

    – Carlton
    Nov 21 '18 at 17:46











  • I am glad that I could help, happy coding :)

    – Pavneet_Singh
    Nov 21 '18 at 17:47

















Thanks again for the help

– Carlton
Nov 21 '18 at 17:46





Thanks again for the help

– Carlton
Nov 21 '18 at 17:46













I am glad that I could help, happy coding :)

– Pavneet_Singh
Nov 21 '18 at 17:47





I am glad that I could help, happy coding :)

– Pavneet_Singh
Nov 21 '18 at 17:47




















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%2f53416365%2fandroid-application-class-not-recognized-in-dagger2-component%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

How to change which sound is reproduced for terminal bell?

Can I use Tabulator js library in my java Spring + Thymeleaf project?

Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents