# org.mockito.exceptions.base.MockitoException: Cannot instantiate @InjectMocks field named 'service' of type 'class com.example.MyService'

- **ID:** `java/mockito-injectmocks-failure`
- **Domain:** java
- **Category:** config_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

@InjectMocks requires a no-arg constructor or constructor injection, but class lacks one or has ambiguous constructors.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 8+ | active | — | — |

## Workarounds

1. **Provide a no-arg constructor in production class** (90% success)
   ```
   public MyService() {
    // default constructor
}
   ```
2. **Use manual construction with mocks** (85% success)
   ```
   MyService service = new MyService(mockDep1, mockDep2);
   ```

## Dead Ends

- **Adding @InjectMocks to a field with private constructor** — Mockito cannot instantiate the class. (70% fail)
- **Using @Spy on the same field** — Spy requires an instance; @InjectMocks is for creating instances. (50% fail)
