2014-05-17 67 views
1

我想從我的android應用程序使用Solrj索引文件,但它似乎無法正常工作。Solrj從Android索引文件

我下面這個LINK

這是我寫的代碼:

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) 

我怎麼能解決這個問題,謝謝提前

回答

1

org.apache.http.impl.client.SystemDefaultHttpClient分類從Httpclient jar和4.2版本。檢查你的classpath中是否有正確的jar。

+0

我的classpath中有正確的jar –