This question already has an answer here:
I have written an application which sends email from an Android device but I get the following exception when I try to send an email:
android.os.NetworkOnMainThreadException
Why is this occurring and how can I fix it?
This exception means that you are trying to do Network related operation on the main UI thread. You need to do either in a seperate thread or in AsyncTask.
The documentation says that:
See How to fix android.os.NetworkOnMainThreadException? and Android - android.os.NetworkOnMainThreadException for more. For getting more help you might need to show more code.
Something like:
This is how to execute the task:
Which SDK version? If 14+ see this link.
the solution is
JUST FOR DEBUG
add these rows
Real Case Put the code on an AsyncTask
then call