android-room

null pointer exception with ROOM database

限于喜欢 提交于 2020-01-25 10:09:27
问题 I am developing an android app using android studio my app has ROOM database when i store in the database a run time error appears and I can not solve it this is my database code @Database(entities = {Cart.class},version = 1,exportSchema = false) public abstract class CartDatabase extends RoomDatabase { private static Context context; public abstract CartDAO cartDAO(); private static CartDatabase instance; public static CartDatabase getInstance() { if (instance == null) { instance = Room

Room TypeConverter not working

我们两清 提交于 2020-01-25 09:19:06
问题 I have an issue with Room not recognizing my converter. Error: Cannot figure out how to save this field into database. You can consider adding a type converter for it. I need to store some maps and sets in my database. What am I doing wrong? Does room not like interfaces or generics? code: (sorry for all the fields and class name, they are a mixture of English and Czech to not have same names as some java classes): Converter (only part) public class MyConverter { /** * makes a string like 1;2

Room - Database gets locked after a delete query

一笑奈何 提交于 2020-01-25 08:34:07
问题 I'm trying to delete a row from my database. When I first delete it for the first time, the row gets removed successfully. After I try to remove another row, I get an error that the db is not open/ is locked. I have posted the logcat and the code. Also, if I delete a row for the first time, it gets delete and when I close the app and open it back again and delete another row, it works. Only if I continue to delete another row without closing the app, I get the error. Here's the log: Caused by

Dagger2 Inject class with parameter (using Room)

僤鯓⒐⒋嵵緔 提交于 2020-01-25 08:17:12
问题 I have a problem with injecting classes with Dagger2 . I am using RoomDatabase for database access. My room setup: Dao's interface noteDao() interface noteTypeDao() interface userDao() NoteRepository @Singleton class NoteRepository @Inject constructor( private val noteDao: NoteDao, private val noteTypeDao: NoteTypeDao, private val userDao: UserDao ) { } AppDatabase @Database(entities = [Note::class, User::class, NoteType::class], version = 1) abstract class AppDatabase : RoomDatabase() {

How to create a new table in Room dynamically?

天涯浪子 提交于 2020-01-25 05:43:09
问题 Help me out please. In my app user is able to create new database tables by pressing a button. User is also able to access this tables later to receive data from them. Currently I utilize good old SQLite via dataBaseHelper class, so I could just public static void createTable(String tableName) { databaseHelper.getWritableDatabase().execSQL("CREATE TABLE IF NOT EXISTS [" + tableName + "] (...columns)"); } and the job was done; Now I want to use Room library in my App instead of DataBaseHelper.

How to automatically set timestamp in room SQLite database?

天涯浪子 提交于 2020-01-24 22:08:41
问题 I am trying to have SQLite create automatic timestamps with CURRENT_TIMESTAMP. I took the liberty of using Google's code: // roomVersion = '2.2.2' @Entity public class Playlist { @PrimaryKey(autoGenerate = true) long playlistId; String name; @Nullable String description; @ColumnInfo(defaultValue = "normal") String category; @ColumnInfo(defaultValue = "CURRENT_TIMESTAMP") String createdTime; @ColumnInfo(defaultValue = "CURRENT_TIMESTAMP") String lastModifiedTime; } @Dao interface PlaylistDao {

How to automatically set timestamp in room SQLite database?

早过忘川 提交于 2020-01-24 22:08:07
问题 I am trying to have SQLite create automatic timestamps with CURRENT_TIMESTAMP. I took the liberty of using Google's code: // roomVersion = '2.2.2' @Entity public class Playlist { @PrimaryKey(autoGenerate = true) long playlistId; String name; @Nullable String description; @ColumnInfo(defaultValue = "normal") String category; @ColumnInfo(defaultValue = "CURRENT_TIMESTAMP") String createdTime; @ColumnInfo(defaultValue = "CURRENT_TIMESTAMP") String lastModifiedTime; } @Dao interface PlaylistDao {

Which approach should i go for regarding relations in Room DB?

痴心易碎 提交于 2020-01-24 19:32:29
问题 I'm doing a simple shop-app to learn more about Room DB in Android and currently I'm a bit confused on which approach is the best to go with when it comes to relations and nested objects. Scenario: Customer choose an item from the shop and orders it. Afterward the database updates the customer-table with the order ID so the customers orders can be searched in the DB. The order-table have the products ID's in that specific order. In customers "account" page (inside the app) , all the orders

What's the minimum Android API level for using new Google's Jetpack components

爱⌒轻易说出口 提交于 2020-01-24 15:12:15
问题 I had started to learn RxJava that I knew there's some new Google's components like LiveData, Databinding, etc. I want to know what is the minimum Android's API level to use them. Can I leverage them for example in an older APIs like 21 or 23? 回答1: Right from the Docs https://developer.android.com/topic/libraries/support-library/. Starting with Support Library release 26.0.0 (July 2017), the minimum supported API level across most support libraries has increased to Android 4.0 (API level 14)

How to create a generic Adapter in Kotlin?

我们两清 提交于 2020-01-24 15:04:28
问题 I have 3 similars adapters and I want to combine them in 1. The only thing that is different is the ArrayList type. I have 2 room entities for room, FavoriteArticle, and HistoryArticle, but they have the same fields as WikiPage. class Adapter<T> (@LayoutRes private val layoutRes: Int) : RecyclerView.Adapter<Holder>() { val currentResult: ArrayList<T> = ArrayList() override fun getItemCount() = currentResult.size override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): Holder { val