Android Room. Let me ask you a question

Asked 2 years ago, Updated 2 years ago, 33 views

We are currently implementing an application that can be translated into a toy project

If you enter Korean to translate and translate into English,

Save to database and

I'm making an application that brings the translated data into a recycling view.

All the work is done on the Fragment

Communication is using the Retrofit2 library

The database is using the Romm library

The problem is that the data received from Retrofit2 is not being inserted

The error currently appears this way.

java.lang.RuntimeException: An error occurred while executing doInBackground() at android.os.AsyncTask$3.done(AsyncTask.java:353) at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383) at java.util.concurrent.FutureTask.setException(FutureTask.java:252) at java.util.concurrent.FutureTask.run(FutureTask.java:271) at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636) at java.lang.Thread.run(Thread.java:764) Caused by: android.database.sqlite.SQLiteConstraintException: NOT NULL constraint failed: language_table.language (code 1299) at android.database.sqlite.SQLiteConnection.nativeExecuteForLastInsertedRowId(Native Method) at android.database.sqlite.SQLiteConnection.executeForLastInsertedRowId(SQLiteConnection.java:789) at android.database.sqlite.SQLiteSession.executeForLastInsertedRowId(SQLiteSession.java:926) at android.database.sqlite.SQLiteStatement.executeInsert(SQLiteStatement.java:86) at android.arch.persistence.db.framework.FrameworkSQLiteStatement.executeInsert(FrameworkSQLiteStatement.java:79) at android.arch.persistence.room.EntityInsertionAdapter.insertAndReturnId(EntityInsertionAdapter.java:114) at com.example.toyproject.Model.LanguageDao_Impl.insert(LanguageDao_Impl.java:96) at com.example.toyproject.Model.LanguageRepository$1.doInBackground(LanguageRepository.java:35) at com.example.toyproject.Model.LanguageRepository$1.doInBackground(LanguageRepository.java:23) at android.os.AsyncTask$2.call(AsyncTask.java:333) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)  at java.lang.Thread.run(Thread.java:764)

I use AsyncTask when I insert in Room, but I think something went wrong in doInbackground I don't know why.

room android

2022-09-22 13:28

1 Answers

Check if the language data to enter language_table is NULL in the retrofit response.

If NULL, set the default value for the variable.

If not, please update the table definition and retrofit result sample to the question.


2022-09-22 13:28

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.