房间持久性库(依赖性问题),MVVM设计模式 [英] Room persistence library (dependency issue), MVVM design pattern
本文介绍了房间持久性库(依赖性问题),MVVM设计模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
遵循MVVM教程,并添加房间依赖性 >
1-我在编译时遇到此错误:
Note: Failed to read get kotlin metadata for [Ljava.lang.Object;@54d771f9
Note: Failed to read get kotlin metadata for [Ljava.lang.Object;@4c00a268
Note: Failed to read get kotlin metadata for [Ljava.lang.Object;@42104314
Note: Failed to read get kotlin metadata for [Ljava.lang.Object;@203b72ad
2-也是这样:(已解决)
error: cannot find symbol class of
在MainActivity
中添加此代码时:
public class MainActivity extends AppCompatActivity {
private NoteViewModel noteViewModel;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//error is here in the ViewModelProviders.of
noteViewModel = new ViewModelProviders.of(this).get(NoteViewModel.class);
noteViewModel.getAllNotes().observe(this, notes -> {
//update RecyclerView
Toast.makeText(MainActivity.this, "onChanged", Toast.LENGTH_SHORT).show();
});
}
}
-
build.gradle(项目):
repositories { google() jcenter() maven { url "https://kotlin.bintray.com/kotlinx/" } } allprojects { repositories { google() jcenter() maven { url "https://kotlin.bintray.com/kotlinx/" } } }
-
build.gradle(app):
room_version = "2.1.0-alpha06" implementation "androidx.room:room-runtime:$room_version" annotationProcessor "androidx.room:room-compiler:$room_version"
解决方案
删除new
,
这将起作用:
noteViewModel = ViewModelProviders.of(this).get(NoteViewModel.class);
Iam following MVVM tutorial and when adding Room dependency
1- I got this this error in compile:
Note: Failed to read get kotlin metadata for [Ljava.lang.Object;@54d771f9
Note: Failed to read get kotlin metadata for [Ljava.lang.Object;@4c00a268
Note: Failed to read get kotlin metadata for [Ljava.lang.Object;@42104314
Note: Failed to read get kotlin metadata for [Ljava.lang.Object;@203b72ad
2- also this: (SOLVED)
error: cannot find symbol class of
when adding this code in MainActivity
:
public class MainActivity extends AppCompatActivity {
private NoteViewModel noteViewModel;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//error is here in the ViewModelProviders.of
noteViewModel = new ViewModelProviders.of(this).get(NoteViewModel.class);
noteViewModel.getAllNotes().observe(this, notes -> {
//update RecyclerView
Toast.makeText(MainActivity.this, "onChanged", Toast.LENGTH_SHORT).show();
});
}
}
build.gradle(project):
repositories { google() jcenter() maven { url "https://kotlin.bintray.com/kotlinx/" } } allprojects { repositories { google() jcenter() maven { url "https://kotlin.bintray.com/kotlinx/" } } }
build.gradle(app):
room_version = "2.1.0-alpha06" implementation "androidx.room:room-runtime:$room_version" annotationProcessor "androidx.room:room-compiler:$room_version"
解决方案
remove new
,
this will work:
noteViewModel = ViewModelProviders.of(this).get(NoteViewModel.class);
这篇关于房间持久性库(依赖性问题),MVVM设计模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文