执行http请求时由AbstractPoolEntry抛出的NullPointerException

时间:2014-09-04 13:35:51

标签: java android httpclient

使用NullPointerException发布http请求时,我得到DefaultHttpClient,如下所示:

java.lang.NullPointerException
at org.apache.http.impl.conn.AbstractPoolEntry.layerProtocol(AbstractPoolEntry.java:305)
at org.apache.http.impl.conn.AbstractPooledConnAdapter.layerProtocol(AbstractPooledConnAdapter.java:146)
at org.apache.http.impl.client.DefaultRequestDirector.establishRoute(DefaultRequestDirector.java:670)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:375)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:653)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:627)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:616)

我检查了AbstractPoolEntry的源代码:

272    public void layerProtocol(HttpContext context, HttpParams params)
273        throws IOException {
274
275        //@@@ is context allowed to be null? depends on operator?
276        if (params == null) {
277            throw new IllegalArgumentException
278                ("Parameters must not be null.");
279        }
280
281        if ((this.tracker == null) || !this.tracker.isConnected()) {
282            throw new IllegalStateException("Connection not open.");
283        }
284        if (!this.tracker.isTunnelled()) {
285            //@@@ allow this?
286            throw new IllegalStateException
287                ("Protocol layering without a tunnel not supported.");
288        }
289        if (this.tracker.isLayered()) {
290            throw new IllegalStateException
291                ("Multiple protocol layering not supported.");
292        }
293
294        // - collect the arguments
295        // - call the operator
296        // - update the tracking data
297        // In this order, we can be sure that only a successful
298        // layering on top of the connection will be tracked.
299
300        final HttpHost target = tracker.getTargetHost();
301
302        connOperator.updateSecureConnection(this.connection, target,
303                                             context, params);
304
305        this.tracker.layerProtocol(this.connection.isSecure());
306
307    } // layerProtocol

似乎它不会在第305行抛出任何异常。

有人能给我一些建议吗?

PS:我将ThreadSafeClientConnManager设置为DefaultHttpClient

0 个答案:

没有答案