Android: Application class not recognized in Dagger2 Component
It seems like I cant find the MyApplication
class from my ApplicationComponent:
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
|
show 1 more comment
It seems like I cant find the MyApplication
class from my ApplicationComponent:
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
android:name="MyApplication"
should beandroid: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
|
show 1 more comment
It seems like I cant find the MyApplication
class from my ApplicationComponent:
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
It seems like I cant find the MyApplication
class from my ApplicationComponent:
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
android dagger-2 dagger
asked Nov 21 '18 at 16:20
CarltonCarlton
95321638
95321638
android:name="MyApplication"
should beandroid: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
|
show 1 more comment
android:name="MyApplication"
should beandroid: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
|
show 1 more comment
1 Answer
1
active
oldest
votes
Apparently looks like a package name issue as component is unable to import it or use it so
Move the Application class under the root package name (that you entered while creating app)
Use
.MyApplication
to register you application class
android:name=".MyApplication"
or may also add any additional package name with application name
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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Apparently looks like a package name issue as component is unable to import it or use it so
Move the Application class under the root package name (that you entered while creating app)
Use
.MyApplication
to register you application class
android:name=".MyApplication"
or may also add any additional package name with application name
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
add a comment |
Apparently looks like a package name issue as component is unable to import it or use it so
Move the Application class under the root package name (that you entered while creating app)
Use
.MyApplication
to register you application class
android:name=".MyApplication"
or may also add any additional package name with application name
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
add a comment |
Apparently looks like a package name issue as component is unable to import it or use it so
Move the Application class under the root package name (that you entered while creating app)
Use
.MyApplication
to register you application class
android:name=".MyApplication"
or may also add any additional package name with application name
Apparently looks like a package name issue as component is unable to import it or use it so
Move the Application class under the root package name (that you entered while creating app)
Use
.MyApplication
to register you application class
android:name=".MyApplication"
or may also add any additional package name with application name
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
android:name="MyApplication"
should beandroid: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