【问题标题】:Can't find `fun Cursor.getString(columnName: String): String` implementation找不到 `fun Cursor.getString(columnName: String): String` 实现
【发布时间】:2019-03-06 23:33:43
【问题描述】:

这些功能在哪里实现?

https://android.github.io/android-ktx/core-ktx/androidx.database/android.database.-cursor/index.html

我看到包 androidx.core.database 但找不到实现。 只有这样的功能。

inline fun Cursor.getBlobOrNull(index: Int) = if (isNull(index)) null else getBlob(index)
inline fun Cursor.getDoubleOrNull(index: Int) = if (isNull(index)) null else getDouble(index)
inline fun Cursor.getFloatOrNull(index: Int) = if (isNull(index)) null else getFloat(index)
inline fun Cursor.getIntOrNull(index: Int) = if (isNull(index)) null else getInt(index)
inline fun Cursor.getLongOrNull(index: Int) = if (isNull(index)) null else getLong(index)
inline fun Cursor.getShortOrNull(index: Int) = if (isNull(index)) null else getShort(index)
inline fun Cursor.getStringOrNull(index: Int) = if (isNull(index)) null else getString(index)

【问题讨论】:

  • 你最近有没有改过版本或者添加了对build.gradle的依赖?您是否尝试在构建之前运行./gradlew clean 任务?
  • 有,但找不到。

标签: android kotlin android-ktx


【解决方案1】:

Cursor 的基于名称的扩展名已被 Jake Wharton 删除。

用他的话来说:

他们鼓励一种低效率的模式。你应该查一下 列名在迭代之前一次或使用更高级别的抽象 比如 Room 或 SQL Delight 可以为您做到这一点。

您可以在此处找到此软件包的完整 git 历史记录: https://android.googlesource.com/platform/frameworks/support/+log/android-room-release/core/ktx/src/main/java/androidx/core/database

【讨论】:

    猜你喜欢
    • 2016-07-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-03
    • 1970-01-01
    • 2016-07-25
    • 2015-04-11
    相关资源
    最近更新 更多