# 错误：找不到字段的 getter。Room 在类 'User' 中找不到字段 'userId' 的 getter。

- **ID:** `android/room-cannot-find-getter`
- **领域:** android
- **类别:** build_error
- **验证级别:** ai_generated
- **修复率:** 95%

## 根因

Room 要求实体中每个字段都有 getter 方法，但该字段为私有且没有公共 getter。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Room 2.4.0+ | active | — | — |
| Android Studio 2021.3+ | active | — | — |

## 解决方案

1. ```
   为字段添加公共 getter 方法：public int getUserId() { return userId; }
   ```
2. ```
   使用 Kotlin 数据类自动生成 getter：data class User(val userId: Int)
   ```
3. ```
   将字段设为包私有或公共（如果不介意破坏封装性）
   ```

## 无效尝试

- **** — Room can still access public fields directly, but it expects getter methods for proper encapsulation and data binding; might cause other issues with data classes. (30% 失败率)
- **** — This excludes the field from persistence entirely, which is not the intended fix. (90% 失败率)
- **** — Room uses JavaBeans naming conventions; renaming without adding getter won't solve the problem. (70% 失败率)
