AndroidX ActivityResultContract: 找不到类/包 - 解决方法
如果你无法找到'androidx.activity.result.contract.ActivityResultContract'类或者'registerForActivityResult()'方法,可能是因为你的项目没有正确引入'androidx.activity:activity-ktx'库。
要解决这个问题,你可以按照以下步骤操作:
- 打开项目的'build.gradle'文件。
- 在'dependencies'部分中添加以下依赖:
注意:请根据你的项目需要选择合适的版本号。implementation 'androidx.activity:activity-ktx:1.4.0' - 同步项目,以确保依赖库被正确引入。
完成上述步骤后,你应该能够找到'androidx.activity.result.contract.ActivityResultContract'类和'registerForActivityResult()'方法,并且可以在你的代码中使用它们了。
原文地址: https://www.cveoy.top/t/topic/qxbk 著作权归作者所有。请勿转载和采集!