我已经使用kotlin
和anko
库创建了一个数据库。我正在关注这篇文章https://antonioleiva.com/databases-anko-kotlin/我正在尝试使用以下方法在数据库块中插入数据,但出现错误
类型干扰失败。预期类型不匹配:找到所需的字符串对
fun insertPerson() {
database.use {
insert(PersonTable.Name,
PersonTable.PersonName to "XX",
PersonTable.Domain to "Technology",
PersonTable.MobileNumber to "XXXXX")
}
}
object PersonTable {
val Name = "Person"
val ID = "id"
val PersonName = "person_name"
val Domain = "domain"
val MobileNumber = "mobile_number"
}
构建.gradle
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.williams.fourthdemo"
minSdkVersion 16
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
compile 'com.android.support:appcompat-v7:25.3.1'
testCompile 'junit:junit:4.12'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile "org.jetbrains.anko:anko-common:0.10.1"
compile "org.jetbrains.anko:anko-sqlite:0.10.1"
}