gpt4 book ai didi

Android Jetpack 撰写 - java.lang.NoSuchMethodError : No virtual method setContent(Lkotlin/jvm/functions/Function0;)

转载 作者:行者123 更新时间:2023-12-04 23:40:18 38 4
gpt4 key购买 nike

我收到了 java.lang.NoSuchMethodError尝试运行时出现异常 setContent{ Composable() } .
完整代码:

class ComposeFragment : Fragment() {

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?) =
ComposeView(requireContext()).apply { setContent { Text("hello") } }

}
完全异常(exception):
java.lang.NoSuchMethodError: No virtual method setContent(Lkotlin/jvm/functions/Function0;)V in class Landroidx/compose/ui/platform/ComposeView; or its super classes (declaration of 'androidx.compose.ui.platform.ComposeView' appears in /data/app/~~3OmVKUoYitZ_S4H81xmyuw==/my.app.package-PAQxAKmtRuhnzp4M2DME8w==/base.apk)
类似问题的解决方案/答案建议添加 buildFeatures { compose = true }kotlinCompilerExtensionVersion ,我已经这样做了,但问题仍然存在。
我完整的 compose Gradle 配置如下:
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
useIR = true
}

buildFeatures {
compose = true
}

composeOptions{
kotlinCompilerExtensionVersion = "1.0.5"
}

implementation( "androidx.activity:activity-compose:1.3.1" )
implementation( "androidx.activity:activity-compose:1.3.1" )
implementation( "androidx.compose.material:material:1.0.5" )
implementation( "androidx.compose.animation:animation:1.0.5" )
implementation( "androidx.compose.ui:ui-tooling:1.0.5" )
implementation( "androidx.lifecycle:lifecycle-viewmodel-compose:1.0.0-alpha07" )
androidTestImplementation( "androidx.compose.ui:ui-test-junit4:1.0.5" )

最佳答案

今天遇到了同样的异常,所以我把我的解决方案放在这里以防其他人需要它。
就我而言,这是因为 build.gradle 中缺少以下设置。文件。
enter image description hereVersion.COMPOSE是撰写版本,在我的情况下是 1.1.0-alpha05

关于Android Jetpack 撰写 - java.lang.NoSuchMethodError : No virtual method setContent(Lkotlin/jvm/functions/Function0;),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70712741/

38 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com