Quantcast
Channel: How can I fix 'android.os.NetworkOnMainThreadException'? - Stack Overflow
Browsing all 191 articles
Browse latest View live
↧

Answer by Krishna for How to fix 'android.os.NetworkOnMainThreadException'?

You are not allowed to implement network operations on the UI thread on Android. You will have to use AsyncTask class to perform network related operations like sending API request, downloading image...

View Article


Answer by rObOtAndChalie for How to fix...

You can actually start a new Thread, I had this problem before and solved it by this way.

View Article


Answer by RevanthKrishnaKumar V. for How to fix...

Accessing network resources from the main (UI) thread cause this exception. Use a separate thread or AsyncTask for accessing a network resource to avoid this problem.

View Article

Answer by Nabin for How to fix 'android.os.NetworkOnMainThreadException'?

In simple words,DO NOT DO NETWORK WORK IN THE UI THREADFor example, if you do an HTTP request, that is a network action.Solution:You have to create a new ThreadOr use AsyncTask classWay:Put all your...

View Article

Answer by Ponsuyambu Velladurai for How to fix...

On Android, network operations cannot be run on the main thread. You can use Thread, AsyncTask (short-running tasks), Service (long-running tasks) to do network operations.

View Article


Answer by prat3ik-patel for How to fix...

You have to simple add following line in manifest.xml after manifest tag<uses-permission android:name="android.permission.INTERNET"/> and in activity file add following code after binding...

View Article

Answer by msysmilu for How to fix 'android.os.NetworkOnMainThreadException'?

Although above there is a huge solution pool, no one mentioned com.koushikdutta.ion: https://github.com/koush/ionIt's also asynchronous and very simple to use:Ion.with(context)...

View Article

Answer by Kacy for How to fix 'android.os.NetworkOnMainThreadException'?

This works. Just made Dr.Luiji's answer a little simpler.new Thread() { @Override public void run() { try { //Your code goes here } catch (Exception e) { e.printStackTrace(); } } }.start();

View Article


Answer by Gurpreet singh for How to fix...

Use the below code to perform heavy tasks.// Your package here import java.util.List; import org.apache.http.NameValuePair; import android.app.Activity; import android.app.ProgressDialog; import...

View Article


Answer by Subhalaxmi for How to fix 'android.os.NetworkOnMainThreadException'?

I solved this problem in a simple way...I added after oncreateStrictMode.enableDefaults(); and solved this.Oruse Service or AsyncTask to solve thisNote:Do not change SDK version Do not use a separate...

View Article

Answer by Kumarsunil for How to fix 'android.os.NetworkOnMainThreadException'?

Android does not allow a separate process into the main activity thread, and the HTTP connection is an independent thread here. That is the reason you are getting the...

View Article

Answer by Vaishali Sutariya for How to fix...

Put your code inside:new Thread(new Runnable(){ @Override public void run() { try { // Your implementation } catch (Exception ex) { ex.printStackTrace(); } } }).start(); Or:class DemoTask extends...

View Article

Answer by amardeep for How to fix 'android.os.NetworkOnMainThreadException'?

This exception occurs due to any heavy task performed on the main thread if that performing task takes too much time.To avoid this, we can handle it using threads or...

View Article


Answer by Ashwin S Ashok for How to fix...

The error is due to executing long running operations in main thread,You can easily rectify the problem by using AsynTask or Thread. You can checkout this library AsyncHTTPClient for better handling....

View Article

Answer by Novak for How to fix 'android.os.NetworkOnMainThreadException'?

Just to spell out something explicitly:The main thread is basically the UI thread.So saying that you cannot do networking operations in the main thread means you cannot do networking operations in the...

View Article


Answer by Oleksiy for How to fix 'android.os.NetworkOnMainThreadException'?

Using Android Annotations is an option. It will allow you to simply run any method in a background thread:// normal method private void normal() { doSomething(); // do something in background }...

View Article

Answer by dhiraj kakran for How to fix...

Use this in Your Activity btnsub.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { new Thread(new Runnable() { @Override public void run() { // TODO Auto-generated...

View Article


Answer by perry for How to fix 'android.os.NetworkOnMainThreadException'?

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.The error is the...

View Article

Answer by Stevie for How to fix 'android.os.NetworkOnMainThreadException'?

The accepted answer has some significant down-sides. It is not advisable to use AsyncTask for networking unless you really know what you are doing. Some of the down-sides include:AsyncTask's created as...

View Article

Answer by Dhruv Jindal for How to fix 'android.os.NetworkOnMainThreadException'?

Network-based operations cannot be run on the main thread. You need to run all network-based tasks on a child thread or implement AsyncTask.This is how you run a task in a child thread:new Thread(new...

View Article
Browsing all 191 articles
Browse latest View live