Solrj to index document from Android

孤者浪人 提交于 2019-12-02 13:07:20

问题


I'm trying to index document using Solrj from my android application, but it seems to not work.

I following this 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();}

But I keep getting this error:

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


回答1:


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.



来源:https://stackoverflow.com/questions/23706673/solrj-to-index-document-from-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!