【问题标题】:Passing args in kotlin using safe args plugin使用安全 args 插件在 kotlin 中传递 args
【发布时间】:2021-09-02 03:56:24
【问题描述】:

我想在 kotlin (android studio) 中通过安全 args 传递 args。无论我尝试什么,我总是在onCreateView 中得到这个error。要求参数是红色的。在 alt+enter 上,它想创建新功能,但这不是我需要的。有谁知道可能是什么问题以及如何解决它。

编辑:Imprts

Imports 1

dependencies in gradle

【问题讨论】:

  • 你能分享你的进口吗?
  • @DinkarKumar 我编辑了帖子并添加了更多导入

标签: android android-studio kotlin parameter-passing android-safe-args


【解决方案1】:
import androidx.navigation.fragment.navArgs

尝试声明一个实例变量,例如 private val args: KrajFragmentArgs by navArgs() 然后从args变量中获取数据。

【讨论】:

    【解决方案2】:

    可能会帮助您使用新的片段版本:

    您需要将 Google Maven 存储库添加到项目的 build.gradle 文件中才能包含此依赖项。

    buildscript {
        ...
    
        repositories {
            google()
            ...
        }
    }
    
    allprojects {
        repositories {
            google()
            ...
        }
    }
    

    要将 AndroidX Fragment 库包含到您的项目中,请在应用的 build.gradle 文件中添加以下依赖项:

    dependencies {
        def fragment_version = "1.3.4"
    
        // Java language implementation
        implementation "androidx.fragment:fragment:$fragment_version"
        // Kotlin
        implementation "androidx.fragment:fragment-ktx:$fragment_version" }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-06-16
      • 1970-01-01
      • 1970-01-01
      • 2018-05-18
      • 2017-11-05
      • 2022-11-02
      • 1970-01-01
      相关资源
      最近更新 更多