【问题标题】:Unresolved reference: setLifecycleOwner in AndroidX未解决的参考:AndroidX 中的 setLifecycleOwner
【发布时间】:2019-10-13 05:10:50
【问题描述】:

MainActivity.kt: (41, 16): 未解析的引用:setLifecycleOwner

任务:app:buildInfoGeneratorDebug

我的应用在我的 gradle.properties 中使用 AndroidX:

android.useAndroidX=true
android.enableJetifier=true

我在 MainActivity.tk 的 onCreate 函数中的代码:

val camera = findViewById<View>(R.id.camera)
    camera.setLifecycleOwner(this)

尝试实现CameraView

【问题讨论】:

  • this 到底是什么?是androidx.appcompat.app.AppCompatActivity吗?
  • @CommonsWare import androidx.appcompat.app.AppCompatActivityclass MainActivity : AppCompatActivity() { }

标签: android kotlin androidx camera-view


【解决方案1】:

您将库视图类型转换为没有这种方法的 android basic View
您应该将findViewById&lt;View&gt; 更改为findViewById&lt;CameraView&gt;

【讨论】:

    猜你喜欢
    • 2019-07-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-02
    • 2021-08-17
    • 2016-12-14
    • 2020-05-27
    • 2019-11-16
    相关资源
    最近更新 更多