Really angry, the Code previously written is re-imported today, causing a lot of problems,
At first, an error was reported. After half a day, it was a version problem. Then Baidu solved the problem.
Http://blog.csdn.net/wang6279026/article/details/8564248
Later, I said that android. OS. networkonmainthreadexception is abnormal. I thought there was a problem with the code I wrote earlier. (I am not very good at network operations ). So I have been searching for code errors. I couldn't find the result, and Baidu found that the version was still a problem. I upgraded all day and I was speechless. A lot of time is wasted.
The upgraded version cannot use HTTP requests in the main thread; otherwise, an error is returned. Maybe the designer has discovered that blocking in the main thread may cause serious consequences. There are two solutions:
One is the well-known handler.
One is to add the following code in the oncreate method:
Strictmode. setthreadpolicy (New strictmode. threadpolicy. builder (). detectdiskreads (). detectdiskwrites (). detectnetwork (). penaltylog (). build (); strictmode. setvmpolicy (New strictmode. vmpolicy. builder (). detectleakedsqlliteobjects (). detectleakedsqlliteobjects (). penaltylog (). penaltydeath (). build ());
Then we can. By the way, do not forget to add network permissions.