android
Android Platform Errors
Exception types and error conditions specific to the Android platform. Covers Activity and Fragment lifecycle, IPC and Binder communication, networking, resource loading, permissions, and SQLite.
16 codes
references developer.android.com/reference/android/
· All codes 16 codes
- ActivityNotFoundException ActivityNotFoundException Thrown by Context.startActivity() when no installed app has an Activity that can handle the given Intent. Check beforehand with PackageManager.resolveActivity(), or wrap the startActivity() call in a try/catch to show the user a friendly error.
- BadTokenException BadTokenException Thrown by WindowManager.addView() when the window token is invalid or the associated Activity has already been destroyed. Typically occurs when showing a dialog or popup after the Activity's onDestroy(). Guard with isFinishing() || isDestroyed() before showing windows.
- CalledFromWrongThreadException CalledFromWrongThreadException Thrown when a View method is called from a thread other than the thread that created the View hierarchy (the main/UI thread). Post UI updates to the main thread via View.post(), Activity.runOnUiThread(), or withContext(Dispatchers.Main) in a coroutine.
- DeadObjectException DeadObjectException Thrown when an IPC call is made on a Binder reference whose remote process has died. Catch DeadObjectException (or its superclass RemoteException) when calling bound service methods and rebind or release the connection gracefully.
- FileUriExposedException FileUriExposedException Thrown (API 24+) when an app attempts to share a file:// URI with another app via an Intent. Replace file:// URIs with content:// URIs generated by FileProvider and declare the FileProvider in AndroidManifest.xml with a <provider> tag.
- IllegalStateException IllegalStateException Thrown when an operation is invalid for the current lifecycle state. Common Android sources: committing a Fragment transaction after onSaveInstanceState (use commitAllowingStateLoss() cautiously), calling getActivity() from a detached Fragment, or accessing a destroyed Activity context.
- NetworkOnMainThreadException NetworkOnMainThreadException Thrown (API 11+) when a blocking network call is made on the main (UI) thread. Move all network I/O to a background thread, Kotlin coroutine (Dispatchers.IO), or an async callback-based library such as OkHttp or Retrofit.
- NotFoundException NotFoundException Thrown by Resources.getDrawable(), getString(), and related methods when the requested resource ID does not exist in the current configuration or package. Verify the resource ID and that the resource file is present in the correct res/ subdirectory.
- OutOfMemoryError OutOfMemoryError Thrown by the Android Runtime when the heap is exhausted. The most common cause is retaining large Bitmap objects or off-screen Views. Use Glide or Coil for image loading (they handle sampling and caching), avoid static references to Context or View, and use LeakCanary to detect leaks.
- RecoverableSecurityException RecoverableSecurityException A SecurityException subclass (API 29+) indicating the operation can be retried after prompting the user for consent. The exception carries a PendingIntent that launches the system consent dialog. Used by MediaStore mutations when modifying files owned by other apps.
- RemoteException RemoteException Base class for IPC-related exceptions thrown by AIDL-generated stub methods. Subclasses include DeadObjectException and TransactionTooLargeException. Always catch RemoteException when invoking bound service methods to handle process death gracefully.
- SecurityException SecurityException Thrown when an app attempts an operation it is not permitted to perform, usually because a required permission has not been declared in AndroidManifest.xml or has not been granted at runtime (API 23+). Request permissions with ActivityCompat.requestPermissions() and check with ContextCompat.checkSelfPermission().
- SQLiteConstraintException SQLiteConstraintException Thrown by Android's SQLite layer when a UNIQUE, NOT NULL, CHECK, or FOREIGN KEY constraint is violated. Subclass of SQLiteException. In Room, this surfaces wrapped as a SQLiteConstraintException or as a Room-specific ConstraintException depending on the conflicting operation.
- SQLiteException SQLiteException Base class for all Android SQLite database errors, including constraint violations, disk full conditions, and database corruption. Consider using Room, which wraps these into more descriptive, typed exceptions and provides compile-time query verification.
- StrictModeViolation StrictModeViolation Reported by StrictMode when an application violates a configured policy, typically disk or network I/O on the main thread, leaked SQLite cursors, or unclosed file descriptors. Enable StrictMode in debug builds via StrictMode.setThreadPolicy() and StrictMode.setVmPolicy() to surface violations during development.
- TransactionTooLargeException TransactionTooLargeException Thrown when an IPC transaction payload exceeds Android's Binder buffer limit (roughly 1 MB per process). Common causes are large Bitmaps or Parcelables in Intent extras or Fragment arguments. Avoid passing large objects via Intents; use a shared ViewModel, a file, or a database instead.