# java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String at android.app.SharedPreferencesImpl.getString

**Code:** `ClassCastException in SharedPreferences getString` · **Category:** Android · **Seen on:** Android, Java

A key was saved as one type and read as another.

## Meaning

SharedPreferences returns the stored type, so reading an Int key with getString throws. Use consistent types per key or migrate with a new key name.

## Common causes

- Key written as Int, read as String
- Library writes the same key
- App update changed the type

## Quick fix

1. Read with the same type used to write
2. Use a new key name
3. Clear the old value

## Detailed fix by platform

### Kotlin

1. `prefs.edit().remove("count").putString("count_v2", value).apply()`

## How to diagnose

1. **Type** — written?
2. **Key** — shared?
3. **Update** — changed type?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/android/sharedpreferences-classcast)
