简体   繁体   English

android应用程序中引发java.lang.NoSuchMethodError

[英]java.lang.NoSuchMethodError is thrown in android application

Im using a pure java project for communicating with an HTTP server. 我使用纯Java项目与HTTP服务器通信。 In this project i'm using Executors.newSingleThreadExecutor() to run a backrground work of an HTTP post request. 在这个项目中,我使用Executors.newSingleThreadExecutor()运行HTTP发布请求的背景工作。

the background operation is processesing the HttpPost request by using DefaultHttpClient.execute(HttpPost) 后台操作正在使用DefaultHttpClient.execute(HttpPost)处理HttpPost请求

when im using this jar in my android project i get exception: 当我在我的android项目中使用此jar时,出现异常:

FATAL EXCEPTION: pool1-thread1
java.lang.NoSuchMethodError: org.apache.http.impl.client.DefaultHttpClient.execute at...

Any idea why I get that? 知道为什么我明白了吗?

Thanks 谢谢

The version of the Apache classes you compiled with doesn't match the version you are executing with, and specifically they are not the same. 编译时使用的Apache类的版本与执行时使用的版本不匹配,特别是它们是不同的。

Compare your DefaultHttpClient class imported in your jar project with the android implementation of DefaultHttpClient. 将您的jar项目中导入的DefaultHttpClient类与Android的DefaultHttpClient实现进行比较。

I would also suggest to build a android library project with same functionality to avoid such errors as not all classes are implemented the same way in android as in java.To learn more on how to build android library project refer- http://developer.android.com/tools/projects/projects-eclipse.html#SettingUpLibraryProject 我还建议构建一个具有相同功能的android库项目,以免发生此类错误,因为并非所有类都在android中以与java中相同的方式实现。要了解有关如何构建android库项目的更多信息,请参见http:// developer。 android.com/tools/projects/projects-eclipse.html#SettingUpLibraryProject

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM