{
  "id": "android/networkonmainthreadexception",
  "signature": "android.os.NetworkOnMainThreadException",
  "signature_zh": "android.os.NetworkOnMainThreadException",
  "regex": "android\\.os\\.NetworkOnMainThreadException",
  "domain": "android",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "Performing a network operation on the main UI thread, which is forbidden by Android's strict mode since Honeycomb.",
  "root_cause_type": "generic",
  "root_cause_zh": "在主 UI 线程上执行网络操作，自 Honeycomb 起 Android 的严格模式禁止此行为。",
  "versions": [
    {
      "version": "Android 3.0+",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "minSdkVersion 11+",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "This only allows cleartext HTTP, but does not move the network call off the main thread.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "AsyncTask is deprecated and can still leak context or cause threading issues; not a modern solution.",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "This only suppresses the exception for debugging, not a production fix; network on main thread still blocks UI.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Use Kotlin Coroutines: wrap network call in viewModelScope.launch(Dispatchers.IO) { ... }",
      "success_rate": 0.95,
      "how": "Use Kotlin Coroutines: wrap network call in viewModelScope.launch(Dispatchers.IO) { ... }",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use RxJava: subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())",
      "success_rate": 0.9,
      "how": "Use RxJava: subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use Thread: new Thread(() -> { /* network call */ runOnUiThread(() -> updateUI()); }).start()",
      "success_rate": 0.8,
      "how": "Use Thread: new Thread(() -> { /* network call */ runOnUiThread(() -> updateUI()); }).start()",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "使用 Kotlin 协程：在 viewModelScope.launch(Dispatchers.IO) { ... } 中包装网络调用",
    "使用 RxJava：subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())",
    "使用 Thread：new Thread(() -> { /* 网络调用 */ runOnUiThread(() -> updateUI()); }).start()"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://developer.android.com/reference/android/os/NetworkOnMainThreadException",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.88,
  "fix_success_rate": 0.92,
  "resolvable": "true",
  "first_seen": "2023-03-15",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}