android-room

Android Room inserts duplicate entities

半城伤御伤魂 提交于 2020-12-29 06:12:15
问题 I'm using Android's Room library for the database interaction in an application and I'm sort of stumped on how to prevent duplicate entries from being inserted into the database. I feel like I must be missing something because this seems like it should be simple to do. I've searched Google for various combinations of words relating to the subject to no avail. I'm essentially using what one of the samples does for inserting and querying. The Entity: @Entity(tableName = "cameras") public class

Android Two Way DataBinding Problem of Ternary Operator Must be Constant

痞子三分冷 提交于 2020-12-23 08:22:32
问题 My EditText is like this: <EditText android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="2" android:text="@={viewModel.isAddCase? ``: `` + viewModel.currentStudent.age}" //problem here android:inputType="number" /> I want the EditText not to show anything (empty String) based on the isAddCase variable, which is a MutableLiveData<Boolean> initilized when the ViewModel class object is created (inside the init{} block). This is the error I got: The expression '(

Android Two Way DataBinding Problem of Ternary Operator Must be Constant

这一生的挚爱 提交于 2020-12-23 08:20:52
问题 My EditText is like this: <EditText android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="2" android:text="@={viewModel.isAddCase? ``: `` + viewModel.currentStudent.age}" //problem here android:inputType="number" /> I want the EditText not to show anything (empty String) based on the isAddCase variable, which is a MutableLiveData<Boolean> initilized when the ViewModel class object is created (inside the init{} block). This is the error I got: The expression '(

onCreate() of RoomDatabase.Callback() was not called after a successful call to .build()

雨燕双飞 提交于 2020-12-11 09:02:33
问题 I have created MovieDatabase using Room Persisdent lib. According to the documentation of onCreate() method in RoomDatabase.Callback, onCreate() to be called after the database is created for the first time, and all the tables were created. What happend after I called buildPersistentDB() is, I received logs from MoviesDatabase class, the class that is annotated with @Database, but the logs from onCreate() in RoomDatabase.Callback were never called despite I called: this.mMovieDatabase = this

createFromAsset and fallbackToDestructiveMigration methods of Room library - no data exists

南楼画角 提交于 2020-12-11 09:01:55
问题 I have a .db file in assets folder. My RoomDatabase class is as the following. I install the app to my device. Then I changed version = 2 in the below class, and make my prepopulated database version 2. Then i renamed one of the columns in my table so that schema is changed. Then i installed the app again. And boom! Room gives me the following error : Room cannot verify the data integrity. Looks like you've changed schema but forgot to update the version number. You can simply fix this by

onCreate() of RoomDatabase.Callback() was not called after a successful call to .build()

对着背影说爱祢 提交于 2020-12-11 08:59:47
问题 I have created MovieDatabase using Room Persisdent lib. According to the documentation of onCreate() method in RoomDatabase.Callback, onCreate() to be called after the database is created for the first time, and all the tables were created. What happend after I called buildPersistentDB() is, I received logs from MoviesDatabase class, the class that is annotated with @Database, but the logs from onCreate() in RoomDatabase.Callback were never called despite I called: this.mMovieDatabase = this

onCreate() of RoomDatabase.Callback() was not called after a successful call to .build()

試著忘記壹切 提交于 2020-12-11 08:59:24
问题 I have created MovieDatabase using Room Persisdent lib. According to the documentation of onCreate() method in RoomDatabase.Callback, onCreate() to be called after the database is created for the first time, and all the tables were created. What happend after I called buildPersistentDB() is, I received logs from MoviesDatabase class, the class that is annotated with @Database, but the logs from onCreate() in RoomDatabase.Callback were never called despite I called: this.mMovieDatabase = this

Android kapt java.lang.UnsatisfiedLinkError Room

巧了我就是萌 提交于 2020-12-11 08:58:25
问题 I'm updating my project to use the jetpack libraries. I executed this in the commandline: ./gradlew :app:kaptDebugKotlin in my project directory, and this error was thrown: e: [kapt] An exception occurred: java.lang.UnsatisfiedLinkError: org.sqlite.core.NativeDB._open_utf8([BI)V at org.sqlite.core.NativeDB._open_utf8(Native Method) at org.sqlite.core.NativeDB._open(NativeDB.java:71) at org.sqlite.core.DB.open(DB.java:174) at org.sqlite.core.CoreConnection.open(CoreConnection.java:220) at org

Android kapt java.lang.UnsatisfiedLinkError Room

半腔热情 提交于 2020-12-11 08:57:14
问题 I'm updating my project to use the jetpack libraries. I executed this in the commandline: ./gradlew :app:kaptDebugKotlin in my project directory, and this error was thrown: e: [kapt] An exception occurred: java.lang.UnsatisfiedLinkError: org.sqlite.core.NativeDB._open_utf8([BI)V at org.sqlite.core.NativeDB._open_utf8(Native Method) at org.sqlite.core.NativeDB._open(NativeDB.java:71) at org.sqlite.core.DB.open(DB.java:174) at org.sqlite.core.CoreConnection.open(CoreConnection.java:220) at org

createFromAsset and fallbackToDestructiveMigration methods of Room library - no data exists

半城伤御伤魂 提交于 2020-12-11 08:56:55
问题 I have a .db file in assets folder. My RoomDatabase class is as the following. I install the app to my device. Then I changed version = 2 in the below class, and make my prepopulated database version 2. Then i renamed one of the columns in my table so that schema is changed. Then i installed the app again. And boom! Room gives me the following error : Room cannot verify the data integrity. Looks like you've changed schema but forgot to update the version number. You can simply fix this by