使用HttpClientBuilder时无法解析静态字段....

时间:2014-04-18 05:49:54

标签: java android httpclient

我试图用这行代码创建一个httpClient实例:

HttpClient httpClient = HttpClientBuilder.create().build();

编译没问题,但是当代码执行时,我收到了这些错误

D/dalvikvm(21590): DexOpt: couldn't find static field Lorg/apache/http/impl/DefaultConnectionReuseStrategy;.INSTANCE
W/dalvikvm(21590): VFY: unable to resolve static field 5520 (INSTANCE) in Lorg/apache/http/impl/DefaultConnectionReuseStrategy;
D/dalvikvm(21590): VFY: replacing opcode 0x62 at 0x0109
D/dalvikvm(21590): DexOpt: couldn't find static field Lorg/apache/http/impl/client/DefaultConnectionKeepAliveStrategy;.INSTANCE
W/dalvikvm(21590): VFY: unable to resolve static field 5720 (INSTANCE) in Lorg/apache/http/impl/client/DefaultConnectionKeepAliveStrategy;
D/dalvikvm(21590): VFY: replacing opcode 0x62 at 0x0111
D/dalvikvm(21590): DexOpt: couldn't find static field Lorg/apache/http/impl/client/DefaultUserTokenHandler;.INSTANCE
W/dalvikvm(21590): VFY: unable to resolve static field 5758 (INSTANCE) in Lorg/apache/http/impl/client/DefaultUserTokenHandler;
D/dalvikvm(21590): VFY: replacing opcode 0x62 at 0x012f
D/dalvikvm(21590): DexOpt: couldn't find static field Lorg/apache/http/impl/NoConnectionReuseStrategy;.INSTANCE
W/dalvikvm(21590): VFY: unable to resolve static field 5538 (INSTANCE) in Lorg/apache/http/impl/NoConnectionReuseStrategy;
D/dalvikvm(21590): VFY: replacing opcode 0x62 at 0x01b4
D/dalvikvm(21590): DexOpt: couldn't find static field Lorg/apache/http/impl/DefaultConnectionReuseStrategy;.INSTANCE
W/dalvikvm(21590): VFY: unable to resolve static field 5520 (INSTANCE) in Lorg/apache/http/impl/DefaultConnectionReuseStrategy;
D/dalvikvm(21590): VFY: replacing opcode 0x62 at 0x01b8
I/dalvikvm(21590): Could not find method org.apache.http.client.protocol.RequestDefaultHeaders.<init>, referenced from method org.apache.http.impl.client.HttpClientBuilder.build
W/dalvikvm(21590): VFY: unable to resolve direct method 15073: Lorg/apache/http/client/protocol/RequestDefaultHeaders;.<init> (Ljava/util/Collection;)V
D/dalvikvm(21590): VFY: replacing opcode 0x70 at 0x01f0
D/dalvikvm(21590): DexOpt: couldn't find static field Lorg/apache/http/impl/client/DefaultHttpRequestRetryHandler;.INSTANCE
W/dalvikvm(21590): VFY: unable to resolve static field 5721 (INSTANCE) in Lorg/apache/http/impl/client/DefaultHttpRequestRetryHandler;
D/dalvikvm(21590): VFY: replacing opcode 0x62 at 0x02db
D/dalvikvm(21590): DexOpt: unable to opt direct call 0x49b4 at 0x212 in Lorg/apache/http/impl/client/HttpClientBuilder;.build
I/dalvikvm(21590): Could not find method org.apache.http.conn.routing.HttpRoute.getLocalSocketAddress, referenced from method org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect
W/dalvikvm(21590): VFY: unable to resolve virtual method 15468: Lorg/apache/http/conn/routing/HttpRoute;.getLocalSocketAddress ()Ljava/net/InetSocketAddress;
D/dalvikvm(21590): VFY: replacing opcode 0x6e at 0x0020
D/dalvikvm(21590): DexOpt: couldn't find static field Lorg/apache/http/message/BasicLineFormatter;.INSTANCE
W/dalvikvm(21590): VFY: unable to resolve static field 6374 (INSTANCE) in Lorg/apache/http/message/BasicLineFormatter;
D/dalvikvm(21590): VFY: replacing opcode 0x62 at 0x0008
W/dalvikvm(21590): Exception Ljava/lang/NoSuchFieldError; thrown while initializing Lorg/apache/http/impl/io/DefaultHttpRequestWriterFactory;
W/dalvikvm(21590): Exception Ljava/lang/NoSuchFieldError; thrown while initializing Lorg/apache/http/impl/conn/ManagedHttpClientConnectionFactory;
I/JPTFB   (21590): WebView Console: ERROR -  

我包含了所有库: HttpClient的-4.3.3.jar 的HttpCore-4.3.2.jar httpmime-4.3.3.jar 共享记录-1.1.3.jar

任何帮助或建议都将不胜感激。

1 个答案:

答案 0 :(得分:2)

当我尝试在Android项目中使用桌面Java版本的Apache HTTP库时,我遇到了同样的问题。对我来说,解决方案就是简单地使用库的Android版本(可在Google Code project site获得)。确保之后删除旧的导入,并用库中的版本替换它们。