January 16, 2015

android.os.NetworkOnMainThreadException

android.os.NetworkOnMainThreadException  is an android runtime exception which occurs when you are trying to run any network or IO related operations from main activity. Android doesn't support to run IO operations directly on the main activity. 

So to avoid this exception, use a thread to do these operations or you can also use AsyncTask class which helps you to run the code in the background.