Causes of the production:
Executing HTTP requests in the main thread after 4.0 will report the error, perhaps because the HTTP request is too long to cause the program to feign death.
Workaround:
1. Add the following code to the OnCreate function inside the activity that initiated the HTTP request
Strictmode.setthreadpolicy (New StrictMode.ThreadPolicy.Builder (). Detectdiskreads (). Detectdiskwrites (). Detectnetwork (). Penaltylog (). build ());
Strictmode.setvmpolicy (New StrictMode.VmPolicy.Builder (). Detectleakedsqlliteobjects (). Detectleakedclosableobjects (). Penaltylog (). Penaltydeath (). build ());
2. use thread, Runnable, handler three classes
Public void oncreate (bundle savedinstancestate) { super.oncreate ( Savedinstancestate); this.setcontentview (R.layout.share_mblog_view); new thread (runnable). Start ();} Handler handler = new handler () { @Override Public void handlemessage (message msg) { super.handlemessage (msg); Bundle data = msg.getdata (); string val = data.getstring ("value");         LOG.I ("MyLog", "request result is-- > " + val"; }}runnable runnable = new runnable () { @Override public void ruN () { message msg = new message (); bundle data = New bundle (); data.putstring ("Value", "request result"); msg.setdata (data); Handler.sendmessage (msg); }}
Android.os.NetworkOnMainThreadException Workaround: