You are getting a network on main thread exception. It is not a good practice to use any type of blocking (or network activity ) on mainthread(i.e your UI thread).
Possible solution:
1.Upon your button click Spawn a thread , In that thread perform your Network activity that you tried to perform.() 2.This solution is not advisable. but still , You can set your manifest to allow network activity on main thread, Google can provide you the manifest commands .
You can google on NetworkOnMainThreadException to know more about it.