# java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example/com.example.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object android.os.Bundle.getSerializable(java.lang.String)' on a null object reference

- **ID:** `android/activity-recreated-savedinstancestate-null`
- **Domain:** android
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 92%

## Root Cause

Activity is recreated (e.g., after rotation or process death) and `savedInstanceState` is null, but the code attempts to retrieve a serializable object from the bundle without null check.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| Android 11 (API 30) | active | — | — |
| Android 14 (API 34) | active | — | — |
| AndroidX Activity 1.8.0 | active | — | — |

## Workarounds

1. **Add a null check before accessing the bundle: `if (savedInstanceState != null) { val data = savedInstanceState.getSerializable("key") }`** (95% success)
   ```
   Add a null check before accessing the bundle: `if (savedInstanceState != null) { val data = savedInstanceState.getSerializable("key") }`
   ```
2. **Use `onSaveInstanceState` to persist data and `onRestoreInstanceState` to restore it safely with null checks: `override fun onRestoreInstanceState(savedInstanceState: Bundle) { super.onRestoreInstanceState(savedInstanceState); if (savedInstanceState.containsKey("key")) { val data = savedInstanceState.getSerializable("key") } }`** (90% success)
   ```
   Use `onSaveInstanceState` to persist data and `onRestoreInstanceState` to restore it safely with null checks: `override fun onRestoreInstanceState(savedInstanceState: Bundle) { super.onRestoreInstanceState(savedInstanceState); if (savedInstanceState.containsKey("key")) { val data = savedInstanceState.getSerializable("key") } }`
   ```

## Dead Ends

- **** — This only prevents recreation due to orientation changes, not process death or other configuration changes (e.g., locale). The NPE still occurs in other scenarios. (70% fail)
- **** — Calling super.onCreate() is already standard practice; the NPE occurs because `savedInstanceState` itself is null, not because it's accessed before super call. (90% fail)
