我正在学习Android Studio,使之能够连接到Elasticsearch以记录和保存用户数据的应用程序。因此,我使用的是Java Low REST API(由https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-low.html公开),但是运行应用程序时出现此错误:
java.lang.NoSuchFieldError: No static field INSTANCE of 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/org.apache.http.legacy.boot.jar)
当我调用build()函数时:
public ElasticConnection(){
builder = RestClient.builder(
new HttpHost("ip.to-elastic-1.aws.found.io", 9200, "https"));
credentialsProvider.setCredentials(AuthScope.ANY,
new UsernamePasswordCredentials("elastic", "password"));
builder.setRequestConfigCallback(
new RestClientBuilder.RequestConfigCallback() {
@Override
public RequestConfig.Builder customizeRequestConfig(RequestConfig.Builder requestConfigBuilder) {
return requestConfigBuilder.setSocketTimeout(10000);
}
});
builder.setHttpClientConfigCallback(new RestClientBuilder.HttpClientConfigCallback() {
@Override
public HttpAsyncClientBuilder customizeHttpClient(
HttpAsyncClientBuilder httpClientBuilder) {
return httpClientBuilder
.setDefaultCredentialsProvider(credentialsProvider);
}
});
esCon = builder.build();
}
这是我的build.gradle:
dependencies {
implementation 'org.elasticsearch.client:elasticsearch-rest-client:6.4.0'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}