NetworkOnMainThreadException异常

解决办法:

在发起Http请求的Activity里面的onCreate函数里面添加如下代码:

        StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
                .detectDiskReads().detectDiskWrites().detectNetwork()
                .penaltyLog().build());
        StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
                .detectLeakedSqlLiteObjects().detectLeakedClosableObjects()
                .penaltyLog().penaltyDeath().build());

其他方法见:http://blog.csdn.net/mad1989/article/details/25964495

posted @ 2017-05-20 23:36  SkyLeo  阅读(106)  评论(0编辑  收藏  举报