CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views
Background code updated a View directly; UI changes must happen on the main thread.
Only the original thread that created a view hierarchy can touch its views Meaning
Callbacks from network libraries, Executors or Dispatchers.IO run off the main thread. Switch back to Main (withContext(Dispatchers.Main), runOnUiThread, LiveData/StateFlow) before touching views.
Common causes
- Updating views inside a background callback
- Coroutine running on Dispatchers.IO touching UI
- Timer/Thread callbacks
⚡ Quick fix
- Use withContext(Dispatchers.Main) or runOnUiThread
- Expose state via StateFlow/LiveData and observe it in the UI
Detailed fix by platform
Kotlin
- kotlin
lifecycleScope.launch { val data = withContext(Dispatchers.IO) { repo.load() } textView.text = data.title // back on Main }
How to diagnose
- Thread — Callback thread
- Code — Where the view is touched
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
Most viewed in Android
- Could not resolve Gradle: Could not resolve all files for configuration / Could not resolve dependency
- INSTALL_FAILED_USER_RESTRICTED INSTALL_FAILED_USER_RESTRICTED: Install canceled by user (Xiaomi/MIUI, Oppo, Vivo)
- INSTALL_PARSE_FAILED_NO_CERTIFICATES INSTALL_PARSE_FAILED_NO_CERTIFICATES / App not installed as package appears to be invalid
Other ways to find it
Where this error sits
Origin: On your device. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 13 Oct 2026