My data class is this code:
import android.content.Context
import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass
@JsonClass(generateAdapter = true)
data class Rate(
@field:Json(name = "name") val code: String,
@field:Json(name = "value") val value: Float
) {
fun getName(context: Context): String? {
return when (code) {
"AED" -> context.getString(R.string.name_aed)
"AFN" -> context.getString(R.string.name_afn)
"ZAR" -> context.getString(R.string.name_zar)
"ZMW" -> context.getString(R.string.name_zmw)
"ZWL" -> context.getString(R.string.name_zwl)
else -> null
}
}
}
Gradle:
plugins {
id 'com.android.application'
id 'kotlin-android'
//apply plugin: 'kotlin-kapt'
//id "org.jetbrains.kotlin.kapt"
id 'kotlin-kapt'
id 'kotlin-android-extensions'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
/*buildFeatures {
viewBinding = true
}*/
...
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.6.0'
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation 'com.squareup.okhttp3:okhttp:3.10.0'
implementation("com.squareup.moshi:moshi:1.12.0")
implementation("com.squareup.moshi:moshi-kotlin:1.12.0")
kapt 'com.squareup.moshi:moshi-kotlin-codegen:1.8.0'
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
implementation "androidx.room:room-runtime:2.3.0"
kapt "androidx.room:room-compiler:2.3.0"
}
When I delete data class, no errors. And this answer doesn't help as you see. How to solve this? Didn't find solution in any post. I'm not sure what's wrong with code. Have you ever experienced something similar?