首页 > 解决方案 > api图像返回null

问题描述

我正在尝试获取我正在使用的 api 的图像,但它被返回 null 并且错误指向我的 Item.java

日志:

C:\Users\matheus.correa_est\Desktop\Pokedex- 
master\app\build\tmp\kapt3\stubs\debug\com\example\pokedex\model\PokemonItem.java:16: error: Cannot 
figure out how to save this field into database. You can consider adding a type converter for it.
    private final com.example.pokedex.model.PokemonImage images = null;
                                                     ^
> Task :app:kaptDebugKotlin FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:kaptDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptExecution
   > java.lang.reflect.InvocationTargetException (no error message)

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more 
log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.5/userguide/command_line_interface.html#sec:command_line_warnings

 BUILD FAILED in 8s
26 actionable tasks: 2 executed, 24 up-to-date

错误在哪里拉(PokemonItem.java)

 private final com.example.pokedex.model.PokemonImage images = null;
@org.jetbrains.annotations.NotNull()

类 PokemonItem

@Entity(tableName = "PokemonItem")
@TypeConverters(Converters::class)

data class PokemonItem(
    @PrimaryKey(autoGenerate = false)
    var id: String = "",
    @SerializedName("name") val nome: String = "",
    val images: PokemonImage,
    val types: List<String>,
    val abilities: List<PokemonAbility>,
    val hp: String = ""

) : Serializable

宝可梦数据:

data class PokemonData(
val data: List<PokemonItem>
)
data class PokemonAbilities(
    var ability: List<PokemonAbility>
)
data class PokemonAbility(
    var name: String,
    var text: String,
    var type: String
): Serializable

 data class PokemonImage(
    @SerializedName("small") val smallImageUrl: String
)

由于这个错误,我的应用程序甚至没有打开,我也尝试为 Image 创建转换器,但我没有成功

标签: androidkotlinmobile

解决方案


推荐阅读