3

我编写了一个 Android 应用程序,它使用来自 Apache 的 HttpComponents 来建立与服务器的连接。

我使用的版本是4.3(最新),一切正常,除了运行时。

我有异常

E/AndroidRuntime( 1699): java.lang.ExceptionInInitializerError
E/AndroidRuntime( 1699):        at org.apache.http.impl.conn.PoolingHttpClientConnectionManager$InternalConnectionFactory.<in
it>(PoolingHttpClientConnectionManager.java:487)
E/AndroidRuntime( 1699):        at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConne
ctionManager.java:147)
E/AndroidRuntime( 1699):        at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConne
ctionManager.java:136)
E/AndroidRuntime( 1699):        at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConne
ctionManager.java:112)
E/AndroidRuntime( 1699):        at net.xnano.weatherlife.util.ApacheHTTP.<init>(ApacheHTTP.java:97)
E/AndroidRuntime( 1699):        at net.xnano.weatherlife.view.WeatherLifeActivity$3.<init>(WeatherLifeActivity.java:105)
E/AndroidRuntime( 1699):        at net.xnano.weatherlife.view.WeatherLifeActivity.onOptionsItemSelected(WeatherLifeActivity.j
ava:105)
E/AndroidRuntime( 1699):        at android.app.Activity.onMenuItemSelected(Activity.java:2548)
E/AndroidRuntime( 1699):        at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:980)
E/AndroidRuntime( 1699):        at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:735)
E/AndroidRuntime( 1699):        at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:149)
E/AndroidRuntime( 1699):        at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:874)
E/AndroidRuntime( 1699):        at com.android.internal.view.menu.ActionMenuView.invokeItem(ActionMenuView.java:547)
E/AndroidRuntime( 1699):        at com.android.internal.view.menu.ActionMenuItemView.onClick(ActionMenuItemView.java:115)
E/AndroidRuntime( 1699):        at android.view.View.performClick(View.java:4204)
E/AndroidRuntime( 1699):        at android.view.View$PerformClick.run(View.java:17355)
E/AndroidRuntime( 1699):        at android.os.Handler.handleCallback(Handler.java:725)
E/AndroidRuntime( 1699):        at android.os.Handler.dispatchMessage(Handler.java:92)
E/AndroidRuntime( 1699):        at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime( 1699):        at android.app.ActivityThread.main(ActivityThread.java:5041)
E/AndroidRuntime( 1699):        at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 1699):        at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime( 1699):        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
E/AndroidRuntime( 1699):        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
E/AndroidRuntime( 1699):        at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 1699): Caused by: java.lang.ExceptionInInitializerError
E/AndroidRuntime( 1699):        at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.<init>(ManagedHttpClientConne
ctionFactory.java:72)
E/AndroidRuntime( 1699):        at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.<init>(ManagedHttpClientConne
ctionFactory.java:84)
E/AndroidRuntime( 1699):        at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.<clinit>(ManagedHttpClientCon
nectionFactory.java:59)
E/AndroidRuntime( 1699):        ... 25 more
E/AndroidRuntime( 1699): Caused by: java.lang.NoSuchFieldError: org.apache.http.message.BasicLineFormatter.INSTANCE
E/AndroidRuntime( 1699):        at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.<init>(DefaultHttpRequestWriterFac
tory.java:52)
E/AndroidRuntime( 1699):        at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.<init>(DefaultHttpRequestWriterFac
tory.java:56)
E/AndroidRuntime( 1699):        at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.<clinit>(DefaultHttpRequestWriterF
actory.java:46)
E/AndroidRuntime( 1699):        ... 28 more

我添加到 libs 文件夹的库(在 jar 存档中)已导出,似乎应用程序使用内部 org.apache.http 包而不是我自己的库。

IDE 是 Intellij Idea。

有没有人解决这个问题之前请帮助我?

4

2 回答 2

1

这个问题在 SO 中出现过几次。我采用的解决方案是使用名为httpclientandroidlib的库的重新打包版本。这在如何使用添加的 jar 中可用的类覆盖 Android Api 类的此问题的较新版本中作为解决方案提出?

于 2013-12-18T19:08:17.060 回答
0

您可以通过下一种方式使用自己的库

com.yourlibrary.MyClass myClass= new com.yourlibrary.MyClass();
于 2013-09-20T13:06:20.180 回答