房间持久化库(依赖问题),MVVM设计模式
Room persistence library (dependency issue), MVVM design pattern
我正在遵循 MVVM 教程并添加 Room dependency
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(应用程序):
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);
2.1.0-alpha04 消除了这些错误,但编译器在一些地方发出了关于 "mCallbacks in RoomDatabase has been deprecated" 的警告。
我在 YouTube 上按照完全相同的教程进行操作,但 运行 遇到了相同的错误:"Note: Failed to read get kotlin metadata..." 个错误。
我已经尝试了“2.1.0-alpha06”、“2.1.0-alpha05”版本的房间依赖项以及 "maven { url "https://kotlin.bintray.com/kotlinx/”依赖项....再次相同错误。
希望有一个更好的答案来清除这些错误。
我正在遵循 MVVM 教程并添加 Room dependency
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(应用程序):
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);
2.1.0-alpha04 消除了这些错误,但编译器在一些地方发出了关于 "mCallbacks in RoomDatabase has been deprecated" 的警告。
我在 YouTube 上按照完全相同的教程进行操作,但 运行 遇到了相同的错误:"Note: Failed to read get kotlin metadata..." 个错误。
我已经尝试了“2.1.0-alpha06”、“2.1.0-alpha05”版本的房间依赖项以及 "maven { url "https://kotlin.bintray.com/kotlinx/”依赖项....再次相同错误。
希望有一个更好的答案来清除这些错误。