1

I use Kotlin and I have Entity class for Android database Room. I wanted to make it Parcelable, but I got this error:

/Users/rafael/AndroidStudioProjects/Cevsen/app/build/tmp/kapt3/stubs/debug/me/aizon/rafaelekol/cevsen/entities/Bab.java
Error:(6, 1) error: Parceler: No @ParcelConstructor annotated constructor and no default empty bean constructor found.
Warning:warning: Supported source version 'RELEASE_7' from annotation processor 'android.arch.persistence.room.RoomProcessor' less than -source '1.8'
/Users/rafael/AndroidStudioProjects/Cevsen/app/build/tmp/kapt3/stubs/debug/me/aizon/rafaelekol/cevsen/database/MyDatabase.java
Warning:(5, 1) warning: Schema export directory is not provided to the annotation processor so we cannot export the schema. You can either provide `room.schemaLocation` annotation processor argument OR set exportSchema to false.
Error:Execution failed for task ':app:kaptDebugKotlin'.
> Internal compiler error. See log for more details

My entity class:

@Parcel(Parcel.Serialization.BEAN)
@Entity(tableName = "bab")
data class Bab (
    @PrimaryKey(autoGenerate = true)
    val uid: Long,

    var id: Int = 0,

    var latin:String = "",

    @SerializedName("latin_text")
    @ColumnInfo(name = "latin_text")
    var latinText:String = "",

    var turkish:String = "",
)

My dependencies:

api 'org.parceler:parceler-api:1.1.9'
kapt 'org.parceler:parceler:1.1.9'
fawaad
  • 341
  • 6
  • 12
Rafael
  • 6,091
  • 5
  • 54
  • 79
  • 2
    have look this https://stackoverflow.com/questions/45300414/room-database-architecture-entity-extends-error – Hemant Parmar Nov 16 '17 at 04:58
  • Data classes have auto-generated multi-argument constructor, that "hides" within the `(...)` block. Try placing `@ParcelConstructor` before the opening brace. – user1643723 Nov 16 '17 at 08:56
  • There is issue with `autoGenerate = true` in `@PrimaryKey`, when I removed `autoGenerate` code started to work – Rafael Nov 17 '17 at 03:07

2 Answers2

0

It seems that 'uid' is a val ,but you make it autoGenerate. Room can't accept this.

yumi0629
  • 86
  • 1
  • 4
0

Below code work for me without error

class Farm(
    @PrimaryKey(autoGenerate = true)
    var farmId: Long = 0,
    var farmerId: Long = 0,
    var farmName: String = AppConstants.EMPTY_STRING,
    var address: String = AppConstants.EMPTY_STRING,
    var area: Int = 0,
    var lat: String = AppConstants.EMPTY_STRING,
    var lng: String = AppConstants.EMPTY_STRING,
) : Parcelable {

    @Ignore
    constructor() : this(0) {
    }
}
Błażej Michalik
  • 4,474
  • 40
  • 55
Vikram
  • 1,072
  • 2
  • 20
  • 33