解决Httpclient.exec(method)不执行或抛出异常的方法

在android4.0后,Http相关操作要放到线程里面。可以通过新建线程来解决。

new Thread(){
public void run(){

代码块

或在activity里面加上如下代码:

StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
        .detectDiskReads()
        .detectDiskWrites()
        .detectAll()   // or .detectAll() for all detectable problems
        .penaltyLog()
        .build());
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
        .detectLeakedSqlLiteObjects()
        .detectLeakedClosableObjects()
        .penaltyLog()
        .penaltyDeath()
        .build());

你可能感兴趣的:(android)