-1

I am using GET METHOD to retrieve data but getting this error Android.os.onMainThreadExpection and i have added the uses permission of INTERNET in the project

inni
  • 464
  • 3
  • 16
  • 1
    post your code looks like `NetworkOnMainThreadException` means running network operation on ui thread – Raghunandan Dec 18 '13 at 07:15
  • for get data from server you have to use AsyncTask to get data. – PankajAndroid Dec 18 '13 at 07:19
  • In android, any time consuming operation is recommended to be performed in a secondary thread. Read this link. http://developer.android.com/training/articles/perf-anr.html – Prem Dec 18 '13 at 07:21
  • @inni: a quick google search for "android network on main thread exception" would give your 1000 results answers to this question. that's why downvote. – Tal Kanel Dec 18 '13 at 07:21

3 Answers3

1

You have a NetworkOnMainThreadException which happens in new versions of Android 3.0 and above if you try to do network operations on the main (UI) Thread. Use an AsyncTask for your network operations.

Sagar Maiyad
  • 12,655
  • 9
  • 63
  • 99
0

But You have to do connection in separate Thread. You can use just Thread or AsyncTask. You can read about that here

Eventually add

StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();

StrictMode.setThreadPolicy(policy); 
Gooziec
  • 2,736
  • 1
  • 13
  • 18
0

You have to put your code that access the internet on a thread

new Thread(new Runnable(){
  @Override
  public void run(){
    //your code that access internet here
  }
}).start();
Rick Royd Aban
  • 904
  • 6
  • 33