# 错误：找不到符号：方法 X 在类 Y 中

- **ID:** `java/cannot-resolve-method-in-object`
- **领域:** java
- **类别:** compilation_error
- **验证级别:** ai_generated
- **修复率:** 92%

## 根因

编译器找不到与调用匹配的方法签名，通常是由于拼写错误、参数类型不正确或类层次结构中缺少方法。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Java 8 | active | — | — |
| Java 11 | active | — | — |
| Java 17 | active | — | — |
| Java 21 | active | — | — |

## 解决方案

1. ```
   Verify the method name and its parameter types against the class's API documentation. For example, if calling `list.sort(null)`, ensure `List` has a `sort` method (Java 8+).
   ```
2. ```
   Add the missing method to the class or use an existing equivalent method. Code example: `list.stream().sorted().collect(Collectors.toList())` instead of `list.sort(null)`.
   ```
3. ```
   Check the classpath for version conflicts: use `mvn dependency:tree` or `gradle dependencies` to ensure the correct version of a library is used that defines the method.
   ```

## 无效尝试

- **** — The method is not defined in the imported class, so the error persists. (70% 失败率)
- **** — Overload resolution fails due to signature mismatch, causing a different compilation error. (60% 失败率)
- **** — Cast may compile but leads to ClassCastException at runtime, not resolving the compile-time error. (50% 失败率)
