You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

BottomSheetFragment中RecyclerView出现Unresolved Reference错误求助

解决Unresolved Reference: menuRecyclerView问题

以下是针对性的排查和修复步骤:

  • 确认XML布局ID完全匹配
    检查fragment_bottom_sheet.xml内RecyclerView的android:id属性是否为@+id/menuRecyclerView,需保证大小写、下划线完全一致,避免出现menu_recyclerView或MenuRecyclerView这类拼写差异。

  • 重新生成View Binding类

    1. 先确认模块的build.gradle(或build.gradle.kts)已启用View Binding:
      android {
          buildFeatures {
              viewBinding true
          }
      }
      
    2. 执行Build > Clean Project,再执行Build > Rebuild Project,强制刷新Binding类缓存,避免旧缓存导致的识别异常。
  • 验证Binding类实例化正确性
    检查MenuBottomSheetFragment中Binding类的初始化代码,确保使用对应布局生成的Binding类:

    private var _binding: FragmentBottomSheetBinding? = null
    private val binding get() = _binding!!
    
    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        _binding = FragmentBottomSheetBinding.inflate(inflater, container, false)
        return binding.root
    }
    

    注意:布局文件名fragment_bottom_sheet.xml对应的Binding类为FragmentBottomSheetBinding,不可混用其他布局的Binding类。

  • 清除IDE缓存
    若为Android Studio识别问题,执行File > Invalidate Caches...,勾选"Invalidate and Restart"后重启IDE,再检查代码识别情况。

  • 确认布局关联正确性
    确保Fragment未通过setContentView或其他方式加载错误布局,必须绑定的是fragment_bottom_sheet.xml。

内容的提问来源于stack exchange,提问作者Om Pal

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.29 23:52:03