Ad
ViewModelProviders Failing Instantation Because "of" Cannot Be Resolved
Im experimenting with view models but, came across an odd error the compiler says it doesn't recognize "of". I already have the the dependency imported in my build.gradle and sycned like so
def ver = "1.1.1"
implementation "android.arch.lifecycle:extensions:$ver"
I made sure it is imported correctly in my activity and instantated. Not sure what to do
import android.arch.lifecycle.ViewModelProviders;
//private BattleRhythmViewModel battleModel;
battleModel = new ViewModelProviders.of(this).get(BattleRhythmViewModel.class);
Ad
Answer
Use ViewModelProviders.of(this).get(BattleRhythmViewModel.class)
of
is a static method. When you call new ViewModelProviders.of(this)
, you are tying to create a new instance of ViewModelProviders
using constructor, but you never called the constructor using ()
.
Ad
source: stackoverflow.com
Related Questions
- → should I choose reactjs+f7 or f7+vue.js?
- → Phonegap Android write to sd card
- → Local reference jquery script in nanohttpd (Android)
- → Click to navigate on mobile devices
- → How to allow api access to android or ios app only(laravel)?
- → Access the Camera and CameraRoll on Android using React Native?
- → React native change listening port
- → What is the default unit of style in React Native?
- → Google play market autocomplete icon
- → Warning: Each child in an array or iterator should have a unique "key" prop. Check the render method of `ListView`
- → Using Laravel with Genymotion
- → react native using like web-based ajax function
- → react native pdf View
Ad