2

私が言ったように、実行しようとすると、これら2つのエラーの間を行ったり来たりしていますHttpClient.execute(HttpPost)。取得IllegalStateException

public class NetMethods {
    private static HttpClient client = new DefaultHttpClient();

    public static void getStuff() {

    ArrayList<Alarm> alarms = new ArrayList<Alarm>();

    HttpPost post = HttpPostFactory.getHttpPost("GetStuff");

    StringBuilder builder = new StringBuilder();

    HttpResponse response = client.execute(post); // Exception thrown here

            ...

また、私のMttpPostFactoryにはこれがあります

import org.apache.http.client.methods.HttpPost;

public class HttpPostFactory {

private static final String url = "http://example.com/ExampleFolder/";

public static HttpPost getHttpPost(String s) {
    return new HttpPost(url + s);
}
}
4

4 に答える 4

0

Androiderのブログから解決策を見つけました:

ログを取得しました:

Invalid use of SingleClientConnManager: connection still allocated.

また

Caused by: java.lang.IllegalStateException: No wrapped connection.

また

Caused by: java.lang.IllegalStateException: Adapter is detached.

最後に解決策を得ました:

public static DefaultHttpClient getThreadSafeClient() {

       DefaultHttpClient client = new DefaultHttpClient();

       ClientConnectionManager mgr = client.getConnectionManager();

       HttpParams params = client.getParams();

       client = new DefaultHttpClient(new ThreadSafeClientConnManager(params,

              mgr.getSchemeRegistry()), params);

       return client;

}
于 2014-12-13T06:22:42.217 に答える