Tag: 领域

境界Kotlin不在架构中

我尝试使用Realm.io在android中存储数据我有RealmClass @RealmClass public open class Alarm : RealmObject() { @Required public open var hourOfDay: Int? = null @Required public open var minute: Int? = null @Required public open var days: BooleanArray? = null public open var name: String? = null } 并在onCreate我尝试添加一些测试数据 override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) mRealm = Realm.getInstance(activity); mRealm.beginTransaction() var a = […]

使用Kotlin无法在项目中设置Realm

我正在尝试用Realm在Kotlin上建立一个测试项目。 这是我的模型: open class Book : RealmObject() { // Standard getters & setters generated by your IDE… @PrimaryKey open var id: Long = 0 open var title = "" open var description = "" open var author = "" open var imageUrl = "" } 这里是我得到的例外: FATAL EXCEPTION: main Process: app.androidhive.info.realm, PID: 18782 java.lang.RuntimeException: Unable […]

Kotlin – 在android中使用Realm模块

我有一个与Realm和一些Realm模块的Android应用程序,帮助我隔离同步Realm,我决定从Java迁移到Kotlin。 @RealmModule(classes = arrayOf(Category::class, Product::class)) private class ShopModule fun getShop(user: SyncUser, path: String): RealmConfiguration { return SyncConfiguration.Builder(user, path) .modules(ShopModule()) .build() } 函数getShop返回RealmConfiguration以在Realm.getInstance()中使用。 经过一些转换后,发生build()时发生了一些错误: io.realm.exceptions.RealmException: Could not find io.realm.ShopModuleMediator 请帮助我继续我的迁移。 我不明白什么是错的,因为这个方法在java中适用于我。 更新: 在评论和许多改善问答后,如此多的改变和尝试在我的项目中,当我的项目中使用kotlin时,发现ShopModuleMediator没有生成,当从Java应用程序项目转换到Kotlin项目已经工作干净的项目。

错误:包含非法的最终字段-Kotlin

我正在使用带有Realm的Kotlin数据类,Gson注释用于从服务器获取数据。 问题:当我在android studio中运行项目时,会出现以下错误 Error:Class "VenderConfig" contains illegal final field "name". 我正在学习Kotlin,所以对此没有太多的想法。 我的VenderConfig类是: @RealmClass class VenderConfig( @SerializedName("name") val name: String? = null, @SerializedName("website") val wb_url: String? = null, @SerializedName("icon") val icon: String? = null, @SerializedName("logo") val logo: String? = null, @SerializedName("description") val description: String? = null, @PrimaryKey @SerializedName("id") val id: Int? = null ) : RealmObject() […]

Android的测试在领域的kotlin

如何才能做一个简单的测试在Android的领域数据库在Kotlin实施测试? 我试图从github上的java realm test中将一个片段调整为kotlin,并得到下一个代码: import io.realm.Realm import io.realm.log.RealmLog import org.hamcrest.CoreMatchers import org.junit.Assert import org.junit.Test import org.junit.Before import org.junit.Rule import org.mockito.Mockito.`when` import org.powermock.api.mockito.PowerMockito import org.powermock.modules.junit4.rule.PowerMockRule class DBTest { @Rule var rule = PowerMockRule() lateinit internal var mockRealm: Realm @Before fun setup() { PowerMockito.mockStatic(RealmLog::class.java) PowerMockito.mockStatic(Realm::class.java) val mockRealm = PowerMockito.mock(Realm::class.java) `when`(Realm.getDefaultInstance()).thenReturn(mockRealm) this.mockRealm = mockRealm } @Test fun shouldBeAbleToGetDefaultInstance() […]

运行kotlin realm demo canon

kotlin版本1.0.0,领域版本0.88.0-SNAPSHOT我下载领域kotlin演示,并运行,如果代码是这样的: var person = Person() person.id = 1 person.name = "Young Person" person.age = 14 realm.beginTransaction() realm.copyToRealm(person) realm.commitTransaction() 抛出异常:引起:java.lang.ClassCastException:io.realm.examples.kotlin.model.Person无法转换为io.realm.PersonRealmProxyInterface 否则我改变这样的代码: realm.beginTransaction() // Add a person var person = realm.createObject(Person::class.java) person.id = 1 person.name = "Young Person" person.age = 14 // When the transaction is committed, all changes a synced to disk. realm.commitTransaction() 那么领域插入一个数据,但person.name,id,年龄为空值或0; 如何解决它

与Realm一起使用“kotlin-kapt”时,构建失败

环境:Android Studio 2.3.3,Gradle 2.3.3和Kotlin 1.1.4-3 当我使用Kotlin创建一个新的Android项目时,一切正常,首先,添加 //in project's build.gradle classpath "io.realm:realm-gradle-plugin:3.5.0" //in app's build.gradle apply plugin: 'realm-android' 好的。 但是在我补充之后 apply plugin: 'kotlin-kapt' 总是提高执行失败 e: Wrong plugin option format: null, should be plugin:<pluginId>:<optionName>=<value> FAILED FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':app:kaptDebugKotlin'. 堆栈跟踪 : * Exception is: org.gradle.api.tasks.TaskExecutionException: Execution […]

kotlin – 领域和包裹

我用android studio开发了android项目。 我想在kotlin中使用onSaveInstanceState()来保存领域对象。 我的代码是 @Parcel( implementations = arrayOf(UserRealmProxy::class), value = Parcel.Serialization.BEAN, analyze = arrayOf(User::class)) open class User : RealmObject() { open var name: String? = null @ParcelPropertyConverter(ListParcelConverter::class) open var Items: RealmList<Item>? = null } 但编译时出现一些错误: 'Unresolved reference: UserRealmProxy' 'An annotation parameter must be a compile-time constant' 当然,UserRealmProxy已经存在了,因为项目已经被编译了。 也@ParcelPropertyConverter(ListParcelConverter::class)不起作用。 它在运行时会导致异常: 'java.io.NotSerializableException: io.realm.RealmList' 但是这个代码在java中编译得很好。 我需要你的帮助。

Realm&Kotlin:DefaultRealmModuleMediator.java – > error:unreachable statement

我正在与Kotlin和Realm合作。 当我尝试构建包含Java和Kotlin文件的项目时, DefaultRealmModuleMediator.java出现以下错误: error: unreachable statement

用kotlin设置领域时出错

我在现有的Android项目中使用了一些kotlin类(已经有领域),kotlin类没有使用任何领域功能,现在在运行时我得到这个错误 :app:compileDebugKotlin Using kotlin incremental compilation :app:compileDebugJavaWithJavac Destination for generated sources was modified by kapt. Previous value = /home/debu/AndroidStudioProjects/WT_Application/app/build/generated/source/apt/debug error: Annotation processor '__gen.AnnotationProcessorWrapper_debug_io_realm_processor_RealmProcessor' not found 1 error :app:compileDebugJavaWithJavac FAILED :app:copyDebugKotlinClasses SKIPPED FAILURE: Build failed with an exception. 我的应用程序的build.gradle apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'realm-android' android { def globalConfiguration = rootProject.extensions.getByName("ext") compileSdkVersion globalConfiguration.getAt("androidCompileSdkVersion") […]