The exception that is thrown when an application attempts to perform a networking operation on its main thread.
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, but it's heavily discouraged
Source: http://developer.android.com/reference/android/os/NetworkOnMainThreadException.html
Solution #1:
Execute the network call in a separeate thread, try using AsyncTask.
Solution #2:
You can use StrictMode object to allow 'network on main thread'.
if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}
P.S.: Use it only if you fully understands the side effects of this solution. You can find more information about StrictMode here.