本文介绍了Solrj 从 Android 索引文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用我的 android 应用程序中的 Solrj 索引文档,但它似乎不起作用.
I'm trying to index document using Solrj from my android application, but it seems to not work.
我关注这个LINK
这是我正在编写的代码:
This is the code I'm writing:
package com.example.secondapp;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.content.IntentSender;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import java.net.MalformedURLException;
import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.apache.solr.client.solrj.response.UpdateResponse;
import org.apache.solr.common.SolrInputDocument;
import org.apache.http.impl.client.DefaultHttpClient;
import ch.boye.httpclientandroidlib.*;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String urlString = "http://10.0.2.2:8983/solr/collection1";
SolrServer solr = new HttpSolrServer(urlString);
SolrInputDocument document = new SolrInputDocument();
document.addField("id", "552199");
document.addField("name", "Gouda cheese wheel");
document.addField("price", "49.99");
// UpdateResponse response = solr.add(document);
// Remember to commit your changes!
//solr.commit();}
但我不断收到此错误:
05-16 20:59:26.036: E/AndroidRuntime(2635): FATAL EXCEPTION: main
05-16 20:59:26.036: E/AndroidRuntime(2635): Process: com.example.secondapp, PID: 2635
05-16 20:59:26.036: E/AndroidRuntime(2635): java.lang.NoClassDefFoundError: org.apache.http.impl.client.SystemDefaultHttpClient
05-16 20:59:26.036: E/AndroidRuntime(2635): at org.apache.solr.client.solrj.impl.HttpClientUtil.createClient(HttpClientUtil.java:112)
05-16 20:59:26.036: E/AndroidRuntime(2635): at org.apache.solr.client.solrj.impl.HttpSolrServer.<init>(HttpSolrServer.java:161)
05-16 20:59:26.036: E/AndroidRuntime(2635): at org.apache.solr.client.solrj.impl.HttpSolrServer.<init>(HttpSolrServer.java:134)
我该如何解决这个问题,提前致谢
how can I solve this problem, Thanks in advance
推荐答案
org.apache.http.impl.client.SystemDefaultHttpClient
类来自 Httpclient jar,从 4.2 版开始.检查您的类路径中是否有正确的 jar.
org.apache.http.impl.client.SystemDefaultHttpClient
class is from Httpclient jar, and from version 4.2. Check whether you have the right jar in your classpath.
这篇关于Solrj 从 Android 索引文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!