领域模型不属于该领域的架构

时间:2018-11-08 21:57:20

标签: android realm

我有这个异常,并且我尝试了许多解决方案,但是都没有解决问题

RealmException:Re_Item_Model不是该领域的架构的一部分

我使用classpath "io.realm:realm-gradle-plugin:5.7.0"

并且此插件我已经确认最后apply plugin: 'realm-android'

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'realm-android'

我的境界模型

 @RealmClass
 open class Re_Item_Model(
 var name: String? = null,
 var year: String? = null,
 var address: String? = null,
 var phone: String? = null,
 var comment: String? = null,
 var khadem: String? = null,
 var done: String? = null,
 var sync: String? = null
 ):RealmObject()

在MainActivity中

fun load(url: String){
    val volley  = Volley.newRequestQueue(this)
    val request = JsonObjectRequest(Request.Method.GET,url,
        Response.Listener {
                response ->
            val array = response.getJSONArray("Admin")
            for (i in 0 until array.length()-1){
                var item = array.getJSONObject(i)
                mrealm.executeTransactionAsync(
                    {
                            realm->
                        var re:Re_Item_Model = realm.createObject(Re_Item_Model::class.java)
                        re.name    = item.getString("name")
                        re.year    = item.getString("year")
                        re.address = item.getString("address")
                        re.phone   = item.getString("phone")
                        re.comment = item.getString("comment")
                        re.khadem  = item.getString("khadem")
                        re.done    = item.getString("done")
                        re.sync    = "0"
                    }, {
                        Toast.makeText(this,"success",Toast.LENGTH_LONG).show()
                    }, {
                            error->
                        Log.e("error",error.toString())
                    })
            }
             val Item = mrealm.where(Re_Item_Model::class.java).findAll()
             Main_Recycler.adapter = Main_recycle_adapter(Item)
        },
        Response.ErrorListener { error->
            if(error is ServerError){
                Toast.makeText(this, "The server could not be found. Please try again after one hour!!", Toast.LENGTH_SHORT).show()
            }else if (error is TimeoutError){
                Toast.makeText(this, "Connection TimeOut! Please check your internet connection.", Toast.LENGTH_SHORT).show()
            }//End else
        }//End error listener
    )//End Request
    volley.add(request)
}

1 个答案:

答案 0 :(得分:0)

您缺少kapt,因此注释处理器不会在Kotlin类上运行。

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'realm-android'