Questions tagged [networkonmainthread]

The exception that is thrown when an Android application attempts to perform a networking operation on its main thread, i.e UI thread.

The thrown when an application attempts to perform a networking operation on its main thread, a.k.a UI thread.

The tag MUST BE USED ONLY with the tag.

203 questions
2708
votes
64 answers

How can I fix 'android.os.NetworkOnMainThreadException'?

I got an error while running my Android project for RssReader. Code: URL url = new URL(urlToRssFeed); SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser parser = factory.newSAXParser(); XMLReader xmlreader =…
bejoy george
  • 29,385
  • 5
  • 19
  • 15
50
votes
10 answers

Android - android.os.NetworkOnMainThreadException

I have this exception and I was reading a thread on this, and it seemed confusing: How to fix android.os.NetworkOnMainThreadException? I already added this line to my manifest: On that…
GeekedOut
  • 16,905
  • 37
  • 107
  • 185
36
votes
3 answers

OkHttp Library - NetworkOnMainThreadException on simple post

I want to use OkHttp library for networking in Android. I started with the simple post example as written in their website: public static final MediaType JSON = MediaType.parse("application/json; charset=utf-8"); OkHttpClient client = new…
Aviv Ben Shabat
  • 1,073
  • 2
  • 13
  • 33
31
votes
5 answers

NetworkOnMainThreadException

I just found out about NetworkOnMainThreadException at official docs and was wondering if the emulator is throwing this. I have been testing my app quite a bit and as far as I know all networking is off the main thread (using Roboguice…
24
votes
0 answers

Caused by: android.os.NetworkOnMainThreadException

Hi all Viewers and readers, I am using link. Whenever I run this code in separate package it works fine, but whenever I am trying to embed this sample in my app, getting Unfortunately app has stopped, only when i click on tab that particular tab…
20
votes
3 answers

How to fix NetworkonMainThreadException in Android?

I'm creating an project for assignment, I'm new to Android, and I wanted to access json from very common url http://api.androidhive.info/contacts/, Problem: I'm trying to read the url and fetch and parse the json returned by this url, I've already…
zzlalani
  • 22,960
  • 16
  • 44
  • 73
10
votes
3 answers

Why I am getting android.os.NetworkOnMainThreadException with AsyncTask?

I am getting android.os.NetworkOnMainThreadException while I have wrote the code of networking operation in AsynkTask. is there any other reason for throwing this exception? Here is my Code: public class Background_confirmation extends…
Juned
  • 6,290
  • 7
  • 45
  • 93
10
votes
2 answers

NetworkOnMainThreadException error in jellybean

I've been trying to get this to work for the last week or so and still have no idea what the problem is. it works on android 2.1 but not on 4.1. ive got this string in a service that check for updates in my app. latestVersion =…
9
votes
4 answers

android.os.NetworkOnMainThreadException on service start on android

after trying my brand new service on android i get this: i guess is something related to the manifest file and permissions, the service is started after the last activity, to update data on server and retrieve new data and save id on sqlite on…
9
votes
3 answers

Quick fix for NetworkOnMainThreadException

I need to execute third-party open source program, which throws NetworkOnMainThreadException. According to SDK reference, this is only thrown for applications targeting the Honeycomb SDK or higher. Applications targeting earlier SDK versions are…
Alex F
  • 42,307
  • 41
  • 144
  • 212
7
votes
2 answers

Retrofit Request Interceptor blocks the main thread

This issue has already been mentioned here, but it is a quite old question and I couldn't find any other information. The Request Interceptor of a Retrofit API call is executed on the main thread. This is an issue when dealing with AccountManager to…
ticofab
  • 7,551
  • 13
  • 49
  • 90
7
votes
2 answers

android.os.NetworkOnMainThreadException in AsyncTask's doInBackground

Why do I get in an AsyncTask which should a android.os.NetworkOnMainThreadException? I thought that an AsyncTask is the solution to that problem. The exxeption is on line 7. private class ImageDownloadTask extends AsyncTask
Sven Mäurer
  • 715
  • 1
  • 9
  • 19
7
votes
1 answer

NetworkOnMainThreadException on Facebook Login with Phonegap 1.6.0

I am currently creating an application using Phonegap 1.6.0 and Sencha Touch 1.1. Recently, when testing on a smartphone with Android 4.0.4, we discovered that the Facebook Login doesn't quite work as expected. We are using the Phonegap Facebook…
Rex
  • 610
  • 9
  • 19
5
votes
3 answers

android.os.NetworkOnMainThreadException inside AsyncTask

I'm building an application and am getting a NetworkOnMainThreadException INSIDE an AsyncTask Call: new POST(this).execute(""); asyncTask: public class POST extends AsyncTask{ private MainActivity form; public…
Joseph Dailey
  • 4,735
  • 2
  • 15
  • 18
5
votes
2 answers

"android.os.NetworkOnMainThreadException" when trying to connect over WiFi using Calimero Java Library

I am using an Android app using a open source java library (Calimero). My code throws an erro when I try to connect over WiFi to a KNXnet/IP router. Here the problem code: private static KNXNetworkLinkIP connect(InetSocketAddress isaLocalEP,…
Mokkapps
  • 2,028
  • 9
  • 42
  • 67
1
2 3
13 14