Hey I'm trying to get my ViewModel working, but no luck so far.
Android Studio shows error Cannot resolve symbol 'ViewModelProviders'
.
Every other question I found on this topic was correcting extends Activity
to extends AppCompatActivity
, but I am extending the right one. Not sure what I'm missing...
My code is based on This YouTube video
MainActivity.java
public class MainActivity extends AppCompatActivity implements
TileAdapter.TileAdapterOnClickHandler {
private BaseViewModel viewModel;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//set Toolbar
Toolbar myToolbar = findViewById(R.id.toolbar);
setSupportActionBar(myToolbar);
//initialize viewModel
viewModel = ViewModelProviders.of(this).get(BaseViewModel.class);
BaseViewModel.java
public class BaseViewModel extends ViewModel {
private Movie[] mMovie;
public void init (Movie[] movies){
this.mMovie = movies;
}
public Movie[] getMovie() {
return mMovie;
}
import
statement, or you do but you do not have the dependency in your Gradle setup. – ShumwayViewModel
under the different package and he is importing it from there – Houseline