0

I'm trying to integrate Parceler library in a Kotlin project with Realm, but I'm facing with problems when I try to adapt an entity to Realm and Parcel.

@Parcel(implementations = { EventRealmProxy::class.java },
        value = Parcel.Serialization.BEAN,
        analyze = { Event::class.java })
@RealmClass
open class Event : Serializable, RealmObject(){

    open var dislike : Boolean = false
    open var like : Boolean = false
    open var blocked : Boolean = false
    open var visits : Boolean = false

}

And this is the error:

Error:(13, 19) Type mismatch: inferred type is () -> Class<Event>
but Array<KClass<(raw) Any>> was expected

I'm trying to find some example of a Class defined with Realm and Parceler in Kotlin.

halfer
  • 19,824
  • 17
  • 99
  • 186
Sami Issa
  • 1,695
  • 1
  • 18
  • 29

2 Answers2

1

I modified your code a little bit. Can you try this?

@Parcel(implementations = arrayOf(EventRealmProxy::class.java),
        value = Parcel.Serialization.BEAN,
        analyze = arrayOf(Event::class))
@RealmClass
open class Event : Serializable, RealmObject(){

    open var dislike : Boolean = false
    open var like : Boolean = false
    open var blocked : Boolean = false
    open var visits : Boolean = false

}

I'm not on my personal computer so i couldn't run code. If it's not working sorry for wasting your time. i'll try to improve my answer when i have time.

savepopulation
  • 11,736
  • 4
  • 55
  • 80
  • Thanks for your answer, but unfortunately doesn't works. These are the errors: `Error:(11, 27) Only 'const val' can be used in constant expressions Error:(11, 35) Unresolved reference: EventRealmProxy Error:(11, 35) An annotation parameter must be a compile-time constant Error:(13, 19) Type inference failed. Expected type mismatch: inferred type is Array> but Array> was expected` – Sami Issa Nov 03 '17 at 10:13
  • i edited my answer. you should put your full log to your question to provide more information about your problem. – savepopulation Nov 03 '17 at 10:17
  • This is the error with your las suggestion: `e: /Users/sami/StudioProjects/project/dat-core-android/datcorelibrary/src/main/java/com/reto/datcorelibrary/model/Event.kt: (24, 27): Only 'const val' can be used in constant expressions e: /Users/sami/StudioProjects/project/dat-core-android/datcorelibrary/src/main/java/com/reto/datcorelibrary/model/Event.kt: (24, 35): Unresolved reference: EventRealmProxy e: /Users/sami/StudioProjects/project/dat-core-android/datcorelibrary/src/main/java/com/reto/datcorelibrary/model/Event.kt: (24, 35): An annotation parameter must be a compile-time constant` – Sami Issa Nov 03 '17 at 10:32
0
@Parcel(implementations = { EventRealmProxy::class.java },

should have been

@Parcel(implementations = [EventRealmProxy::class.java],
EpicPandaForce
  • 79,669
  • 27
  • 256
  • 428