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

时间:2022-02-26 05:37:25

I was trying to create an httpClient instance with this line of code:

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

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

Compiling is ok but when the code is executed, I got these errors

编译是可以的,但是当代码执行时,我得到了这些错误

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 -  
#

I have all of the libraries included: httpclient-4.3.3.jar httpcore-4.3.2.jar httpmime-4.3.3.jar commons-logging-1.1.3.jar

我有包括的所有库:httpclient-4.3.3。jar httpcore-4.3.2。jar httpmime-4.3.3。jar commons-logging-1.1.3.jar

Any help or suggestion would be appreciated.

如有任何帮助或建议,我们将不胜感激。

1 个解决方案

#1


2  

I had the same problem when I tried to use the desktop Java versions of the Apache HTTP libraries in an Android project. The solution for me was to simply resort to the Android build of the library (available at the Google Code project site). Make sure to remove the old imports afterwards and replace them by the versions from the library.

当我尝试在Android项目中使用Apache HTTP库的桌面Java版本时,也遇到了同样的问题。对我来说,解决方案就是使用库的Android构建(可以在谷歌代码项目站点上获得)。确保在之后删除旧的导入,并将其替换为来自库的版本。

#1


2  

I had the same problem when I tried to use the desktop Java versions of the Apache HTTP libraries in an Android project. The solution for me was to simply resort to the Android build of the library (available at the Google Code project site). Make sure to remove the old imports afterwards and replace them by the versions from the library.

当我尝试在Android项目中使用Apache HTTP库的桌面Java版本时,也遇到了同样的问题。对我来说,解决方案就是使用库的Android构建(可以在谷歌代码项目站点上获得)。确保在之后删除旧的导入,并将其替换为来自库的版本。