# java.util.MissingResourceException：找不到基本名称的资源包

- **ID:** `java/missing-resource-bundle`
- **领域:** java
- **类别:** resource_error
- **验证级别:** ai_generated
- **修复率:** 90%

## 根因

ResourceBundle.getBundle() 方法找不到指定基本名称的属性文件或类包，通常是由于缺少文件、类路径不正确或区域设置错误。

## 版本兼容性

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

## 解决方案

1. ```
   Ensure the properties file exists in the classpath at the correct location. For example, if base name is `com.example.messages`, place `messages.properties` in `src/main/resources/com/example/`.
   ```
2. ```
   Use the full qualified base name with package: `ResourceBundle.getBundle("com.example.i18n.messages")` and ensure the file is at `com/example/i18n/messages.properties`.
   ```
3. ```
   Provide a default locale bundle to avoid fallback issues: add `messages.properties` (without locale suffix) as a fallback.
   ```

## 无效尝试

- **** — ResourceBundle expects a .properties file or a class; an empty file with wrong extension is ignored. (80% 失败率)
- **** — ResourceBundle falls back to the default locale, which may also be missing, causing the same error. (70% 失败率)
- **** — The base name must include the full package path; moving the file without updating the name breaks the lookup. (90% 失败率)
