未解决的参考:片段

问题描述 投票:0回答:2

我的 kotlin 代码中遇到了一些错误。 代码如下:

'''package com.mohamed.focuscounter

import android.os.Bundle
import androidx.fragment.app.Fragment                        //(line4)
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup'''

'''class AvailableFragment : Fragment() {                       //(line 9)
    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_available, container, false)
    }
}'''

 The Errors encountered is as follows:
   1.unresolved reference:fragment (line 4)
   2.unresolved reference:Fragment (line 9)

任何帮助将不胜感激

android android-studio kotlin android-fragments
2个回答
0
投票

确保您的应用程序中有 Fragment 的依赖项

build.gradle
文件

implementation "androidx.fragment:fragment-ktx:1.5.5"

0
投票

您可能需要降级您的

androidx-fragment-ktx
版本。在新配置中打开

libs.versions.toml

归档并将

fragmentKtx
的版本降级到某些受支持的较低版本。

获取迄今为止发布的所有不同版本的链接: https://androidx.tech/artifacts/fragment/fragment-ktx/

例如

fragmentKtx = "1.6.0"

© www.soinside.com 2019 - 2024. All rights reserved.