The exception that is thrown when an application attempts to perform a networking operation on its main thread.
means you are trying to run network operation from UI Thread so put your all network related code inside AsyncTask's
doInBackground method and use
onPostExecute for updating UI when
doInBackground method execution complete
and if your are using API LEVEL 9 or GREATER FROM 9 then add StrictMode in onCreate of Activity to avoid this error
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder() .detectDiskReads() .detectDiskWrites() .detectNetwork() .penaltyLog() .build());