Stay organized with collections
Save and categorize content based on your preferences.
NetworkOnMainThreadException
open class NetworkOnMainThreadException : RuntimeException
The exception that is thrown when an application attempts to perform a networking operation on its main thread.
This is only thrown for applications targeting the Honeycomb SDK or higher. Applications targeting earlier SDK versions are allowed to do networking on their main event loop threads, but it's heavily discouraged. See the document Designing for Responsiveness.
Also see StrictMode
.
Summary
Public constructors
NetworkOnMainThreadException
NetworkOnMainThreadException()
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[null,null,["Last updated 2025-02-10 UTC."],[],[],null,["# NetworkOnMainThreadException\n\nAdded in [API level 11](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)\n\nNetworkOnMainThreadException\n============================\n\n*** ** * ** ***\n\nKotlin \\|[Java](/reference/android/os/NetworkOnMainThreadException \"View this page in Java\") \n\n```\nopen class NetworkOnMainThreadException : RuntimeException\n```\n\n|---|---|---|---|----------------------------------------------|\n| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html) |||||\n| ↳ | [kotlin.Throwable](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-throwable/index.html) ||||\n| | ↳ | [java.lang.Exception](../../java/lang/Exception.html#) |||\n| | | ↳ | [java.lang.RuntimeException](../../java/lang/RuntimeException.html#) ||\n| | | | ↳ | [android.os.NetworkOnMainThreadException](#) |\n\nThe exception that is thrown when an application attempts to perform a networking operation on its main thread.\n\nThis is only thrown for applications targeting the Honeycomb SDK or higher. Applications targeting earlier SDK versions are allowed to do networking on their main event loop threads, but it's heavily discouraged. See the document [Designing for Responsiveness](https://developer.android.com/guide/practices/design/responsiveness.html).\n\nAlso see [StrictMode](/reference/kotlin/android/os/StrictMode).\n\nSummary\n-------\n\n| Public constructors ||\n|----------------------------------------------------------------------------|---|\n| [NetworkOnMainThreadException](#NetworkOnMainThreadException())`()` \u003cbr /\u003e |\n\nPublic constructors\n-------------------\n\n### NetworkOnMainThreadException\n\n```\nNetworkOnMainThreadException()\n```"]]