[英]NoSuchFieldError in Android Studio project
我正在尝试将我的Android Studio - 应用程序连接到Exchange Web服务,但我不断收到以下错误:
java.lang.NoSuchFieldError: No static field INSTANCE of type Lorg/apache/http/message/BasicLineFormatter; in class Lorg/apache/http/message/BasicLineFormatter; or its superclasses (declaration of 'org.apache.http.message.BasicLineFormatter' appears in /system/framework/ext.jar)
这是我在android项目中添加到/ libs /的.jars:
这是onCreate方法发生错误:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ExchangeService service = new ExchangeService(); // this is where the error is hitting
ExchangeCredentials credentials = new WebCredentials("user", "pw");
service.setCredentials(credentials);
try {
service.setUrl(new URI("uri"));
} catch (URISyntaxException e) {
e.printStackTrace();
}
EmailMessage msg= null;
try {
msg = new EmailMessage(service);
msg.setSubject("Hello world!");
msg.setBody(MessageBody.getMessageBodyFromText("Sent using the EWS Java API."));
msg.getToRecipients().add("email");
msg.send();
} catch (Exception e) {
e.printStackTrace();
}
}
我的依赖:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:19.0.0'
//compile 'org.apache.httpcomponents:httpclient:4.3'
//compile 'org.apache.httpcomponents:httpcore:4.3.3'
//compile 'commons-logging:commons-logging:1.2'
// compile 'joda-time:joda-time:2.7'
compile group: 'org.apache.httpcomponents' , name: 'httpclient-android' , version: '4.3.5.1'
}
我目前正在研究一个mac(如果屏幕截图没有放弃它),并且如Android应用程序中的Android Studio中所述。
问题源于尝试在Android上使用不同的(通常是更新的)apache httpcomponents版本而不是操作系统附带的版本。
这些版本通常是API不兼容的,但使用相同的类名,导致可怕的
Multiple dex files define Lorg/apache/http/Consts;
或类似的编译时错误消息。
一般来说,你会遇到一些问题,试图在android上使用不同版本的httpcomponents
而不是android提供的一个版本。
股票Android版本似乎没有被指定,但大多数消息来源似乎都同意它是基于httpcomponents-4.0.1
的修改版本。 但是,android SDK包含httpclient
4.1.1
版本(在tools/lib/httpclient-4.1.1.jar
)。
我认为最常见的解决方案是避免使用较新版本的httpcomponents。
Apache现在还提供了httpclient的自定义版本。 但是,正如您自己注意到的,这仍然会导致问题。
当您需要httpcomponents的其他子部分时,问题会变得更糟,例如httpmime
,它会httpmime
各自版本的httpcomponent jar。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.