# java.lang.NumberFormatException: For input string: "..."

- **ID:** `java/numberformatexception-for-input-string`
- **Domain:** java
- **Category:** type_error
- **Verification:** ai_generated
- **Fix Rate:** 90%

## Root Cause

Attempting to parse a string that does not contain a parsable number, often due to whitespace, null, or unexpected characters.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| Java 8 | active | — | — |
| Java 11 | active | — | — |
| Java 17 | active | — | — |
| Java 21 | active | — | — |

## Workarounds

1. **Use try-catch with NumberFormatException and provide a default value: 'int value; try { value = Integer.parseInt(input.trim()); } catch (NumberFormatException e) { value = 0; }'** (90% success)
   ```
   Use try-catch with NumberFormatException and provide a default value: 'int value; try { value = Integer.parseInt(input.trim()); } catch (NumberFormatException e) { value = 0; }'
   ```
2. **Validate input with a regex before parsing: 'if (input != null && input.matches("\\d+")) { int value = Integer.parseInt(input); } else { /* handle error */ }'** (85% success)
   ```
   Validate input with a regex before parsing: 'if (input != null && input.matches("\\d+")) { int value = Integer.parseInt(input); } else { /* handle error */ }'
   ```

## Dead Ends

- **** — Using Integer.valueOf() without try-catch on user input will crash the application if input is invalid. (95% fail)
- **** — Assuming locale-specific number formats (e.g., commas in European locales) are supported by default can cause parsing failures. (80% fail)
