我最近在
但是,按照那里的所有步驟之后,我仍然收到add如下所示的錯誤

我可以使用它輕松修復它
supportFragmentManager.commit {
setReorderingAllowed(true)
add(R.id.container, MainFragment())
}
但很好奇為什么它不起作用?我錯過了什么嗎?
只是為了提供背景關系,我imports的如下
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.example.activityfragmentviewmodel.ui.main.MainFragment
import androidx.fragment.app.commit
我的庫依賴項是
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
implementation "androidx.fragment:fragment-ktx:1.4.0"
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.4.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.0'
uj5u.com熱心網友回復:
add檔案使用的具體化方法是擴展方法,這意味著您需要匯入它,就像您匯入的commit擴展方法一樣:
import androidx.fragment.app.add
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/404530.html
標籤:
上一篇:Linux 行程卡住了怎么辦?
