error: no suitable method found for method ViewModelProviders.of(Fragment,Factory)
Trying to provde ViewModel
via ViewModelProviers.of()
to my activity.
My activity extends AppCompatActivity
but I still see this error:
error: no suitable method found for
of(StartActivity,StartViewModelFactory) method
ViewModelProviders.of(Fragment,Factory) is not applicable (argument
mismatch; StartActivity cannot be converted to Fragment) method
ViewModelProviders.of(FragmentActivity,Factory) is not applicable
(argument mismatch; StartActivity cannot be converted to
FragmentActivity)
Dependency Injection is provided with Dagger 2. Below is my Activity class StartActivity:
public class StartActivity extends AppCompatActivity {
@Inject
StartViewModelFactory startViewModelFactory;
StartModelView startModelView;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
AndroidInjection.inject(this);
super.onCreate(savedInstanceState);
startModelView = ViewModelProviders.of(this, startViewModelFactory).
get(StartViewModel.class);
}
If I understand correctly you should be able to send in an activity in ViewModelProviders.of()
method if they extend AppCompatActivity or Fragment. But I get this error. Any help would be appreciated.
android mvvm viewmodel dagger-2
add a comment |
Trying to provde ViewModel
via ViewModelProviers.of()
to my activity.
My activity extends AppCompatActivity
but I still see this error:
error: no suitable method found for
of(StartActivity,StartViewModelFactory) method
ViewModelProviders.of(Fragment,Factory) is not applicable (argument
mismatch; StartActivity cannot be converted to Fragment) method
ViewModelProviders.of(FragmentActivity,Factory) is not applicable
(argument mismatch; StartActivity cannot be converted to
FragmentActivity)
Dependency Injection is provided with Dagger 2. Below is my Activity class StartActivity:
public class StartActivity extends AppCompatActivity {
@Inject
StartViewModelFactory startViewModelFactory;
StartModelView startModelView;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
AndroidInjection.inject(this);
super.onCreate(savedInstanceState);
startModelView = ViewModelProviders.of(this, startViewModelFactory).
get(StartViewModel.class);
}
If I understand correctly you should be able to send in an activity in ViewModelProviders.of()
method if they extend AppCompatActivity or Fragment. But I get this error. Any help would be appreciated.
android mvvm viewmodel dagger-2
add a comment |
Trying to provde ViewModel
via ViewModelProviers.of()
to my activity.
My activity extends AppCompatActivity
but I still see this error:
error: no suitable method found for
of(StartActivity,StartViewModelFactory) method
ViewModelProviders.of(Fragment,Factory) is not applicable (argument
mismatch; StartActivity cannot be converted to Fragment) method
ViewModelProviders.of(FragmentActivity,Factory) is not applicable
(argument mismatch; StartActivity cannot be converted to
FragmentActivity)
Dependency Injection is provided with Dagger 2. Below is my Activity class StartActivity:
public class StartActivity extends AppCompatActivity {
@Inject
StartViewModelFactory startViewModelFactory;
StartModelView startModelView;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
AndroidInjection.inject(this);
super.onCreate(savedInstanceState);
startModelView = ViewModelProviders.of(this, startViewModelFactory).
get(StartViewModel.class);
}
If I understand correctly you should be able to send in an activity in ViewModelProviders.of()
method if they extend AppCompatActivity or Fragment. But I get this error. Any help would be appreciated.
android mvvm viewmodel dagger-2
Trying to provde ViewModel
via ViewModelProviers.of()
to my activity.
My activity extends AppCompatActivity
but I still see this error:
error: no suitable method found for
of(StartActivity,StartViewModelFactory) method
ViewModelProviders.of(Fragment,Factory) is not applicable (argument
mismatch; StartActivity cannot be converted to Fragment) method
ViewModelProviders.of(FragmentActivity,Factory) is not applicable
(argument mismatch; StartActivity cannot be converted to
FragmentActivity)
Dependency Injection is provided with Dagger 2. Below is my Activity class StartActivity:
public class StartActivity extends AppCompatActivity {
@Inject
StartViewModelFactory startViewModelFactory;
StartModelView startModelView;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
AndroidInjection.inject(this);
super.onCreate(savedInstanceState);
startModelView = ViewModelProviders.of(this, startViewModelFactory).
get(StartViewModel.class);
}
If I understand correctly you should be able to send in an activity in ViewModelProviders.of()
method if they extend AppCompatActivity or Fragment. But I get this error. Any help would be appreciated.
android mvvm viewmodel dagger-2
android mvvm viewmodel dagger-2
edited Nov 21 '18 at 14:55
Carlton
asked Nov 21 '18 at 14:37
CarltonCarlton
93421436
93421436
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
you should be using
.get(StartModelView.class);
and not
.get(StartViewModelFactory.class);
the factory provided to of()
is used by android to generate an instance of your ViewModel
subclass
Thanks, That is true. I added it in my code & this question. But the problem is still there. What could it persists? Could it have something to do with dependency injection?
– Carlton
Nov 21 '18 at 14:56
It looks like you were correct. There was also another underlying problem with my modelviewfactory. I get a "uses uncecked or unsafe operations" from this line@NonNull @Override public <T extends ViewModel> T create(@NonNull Class<T> modelClass) { return (T) new StartModelView(getAllWalletsInteractor); }
DO you know why?
– Carlton
Nov 21 '18 at 15:19
that's normal, it is the way generics work on java.
– Blackbelt
Nov 21 '18 at 15:24
Should I add @SuppressWarning annotation to it?
– Carlton
Nov 21 '18 at 15:26
as you wish. It is a warning not an error
– Blackbelt
Nov 21 '18 at 15:45
|
show 1 more 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%2f53414435%2ferror-no-suitable-method-found-for-method-viewmodelproviders-offragment-factor%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
you should be using
.get(StartModelView.class);
and not
.get(StartViewModelFactory.class);
the factory provided to of()
is used by android to generate an instance of your ViewModel
subclass
Thanks, That is true. I added it in my code & this question. But the problem is still there. What could it persists? Could it have something to do with dependency injection?
– Carlton
Nov 21 '18 at 14:56
It looks like you were correct. There was also another underlying problem with my modelviewfactory. I get a "uses uncecked or unsafe operations" from this line@NonNull @Override public <T extends ViewModel> T create(@NonNull Class<T> modelClass) { return (T) new StartModelView(getAllWalletsInteractor); }
DO you know why?
– Carlton
Nov 21 '18 at 15:19
that's normal, it is the way generics work on java.
– Blackbelt
Nov 21 '18 at 15:24
Should I add @SuppressWarning annotation to it?
– Carlton
Nov 21 '18 at 15:26
as you wish. It is a warning not an error
– Blackbelt
Nov 21 '18 at 15:45
|
show 1 more comment
you should be using
.get(StartModelView.class);
and not
.get(StartViewModelFactory.class);
the factory provided to of()
is used by android to generate an instance of your ViewModel
subclass
Thanks, That is true. I added it in my code & this question. But the problem is still there. What could it persists? Could it have something to do with dependency injection?
– Carlton
Nov 21 '18 at 14:56
It looks like you were correct. There was also another underlying problem with my modelviewfactory. I get a "uses uncecked or unsafe operations" from this line@NonNull @Override public <T extends ViewModel> T create(@NonNull Class<T> modelClass) { return (T) new StartModelView(getAllWalletsInteractor); }
DO you know why?
– Carlton
Nov 21 '18 at 15:19
that's normal, it is the way generics work on java.
– Blackbelt
Nov 21 '18 at 15:24
Should I add @SuppressWarning annotation to it?
– Carlton
Nov 21 '18 at 15:26
as you wish. It is a warning not an error
– Blackbelt
Nov 21 '18 at 15:45
|
show 1 more comment
you should be using
.get(StartModelView.class);
and not
.get(StartViewModelFactory.class);
the factory provided to of()
is used by android to generate an instance of your ViewModel
subclass
you should be using
.get(StartModelView.class);
and not
.get(StartViewModelFactory.class);
the factory provided to of()
is used by android to generate an instance of your ViewModel
subclass
answered Nov 21 '18 at 14:43
BlackbeltBlackbelt
129k23221246
129k23221246
Thanks, That is true. I added it in my code & this question. But the problem is still there. What could it persists? Could it have something to do with dependency injection?
– Carlton
Nov 21 '18 at 14:56
It looks like you were correct. There was also another underlying problem with my modelviewfactory. I get a "uses uncecked or unsafe operations" from this line@NonNull @Override public <T extends ViewModel> T create(@NonNull Class<T> modelClass) { return (T) new StartModelView(getAllWalletsInteractor); }
DO you know why?
– Carlton
Nov 21 '18 at 15:19
that's normal, it is the way generics work on java.
– Blackbelt
Nov 21 '18 at 15:24
Should I add @SuppressWarning annotation to it?
– Carlton
Nov 21 '18 at 15:26
as you wish. It is a warning not an error
– Blackbelt
Nov 21 '18 at 15:45
|
show 1 more comment
Thanks, That is true. I added it in my code & this question. But the problem is still there. What could it persists? Could it have something to do with dependency injection?
– Carlton
Nov 21 '18 at 14:56
It looks like you were correct. There was also another underlying problem with my modelviewfactory. I get a "uses uncecked or unsafe operations" from this line@NonNull @Override public <T extends ViewModel> T create(@NonNull Class<T> modelClass) { return (T) new StartModelView(getAllWalletsInteractor); }
DO you know why?
– Carlton
Nov 21 '18 at 15:19
that's normal, it is the way generics work on java.
– Blackbelt
Nov 21 '18 at 15:24
Should I add @SuppressWarning annotation to it?
– Carlton
Nov 21 '18 at 15:26
as you wish. It is a warning not an error
– Blackbelt
Nov 21 '18 at 15:45
Thanks, That is true. I added it in my code & this question. But the problem is still there. What could it persists? Could it have something to do with dependency injection?
– Carlton
Nov 21 '18 at 14:56
Thanks, That is true. I added it in my code & this question. But the problem is still there. What could it persists? Could it have something to do with dependency injection?
– Carlton
Nov 21 '18 at 14:56
It looks like you were correct. There was also another underlying problem with my modelviewfactory. I get a "uses uncecked or unsafe operations" from this line
@NonNull @Override public <T extends ViewModel> T create(@NonNull Class<T> modelClass) { return (T) new StartModelView(getAllWalletsInteractor); }
DO you know why?– Carlton
Nov 21 '18 at 15:19
It looks like you were correct. There was also another underlying problem with my modelviewfactory. I get a "uses uncecked or unsafe operations" from this line
@NonNull @Override public <T extends ViewModel> T create(@NonNull Class<T> modelClass) { return (T) new StartModelView(getAllWalletsInteractor); }
DO you know why?– Carlton
Nov 21 '18 at 15:19
that's normal, it is the way generics work on java.
– Blackbelt
Nov 21 '18 at 15:24
that's normal, it is the way generics work on java.
– Blackbelt
Nov 21 '18 at 15:24
Should I add @SuppressWarning annotation to it?
– Carlton
Nov 21 '18 at 15:26
Should I add @SuppressWarning annotation to it?
– Carlton
Nov 21 '18 at 15:26
as you wish. It is a warning not an error
– Blackbelt
Nov 21 '18 at 15:45
as you wish. It is a warning not an error
– Blackbelt
Nov 21 '18 at 15:45
|
show 1 more 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%2f53414435%2ferror-no-suitable-method-found-for-method-viewmodelproviders-offragment-factor%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