Hello,

I would like to use Apace Lucene, but this does not seem to work. I
have created an Android project using Eclipse and added "lucene-
core-2.3.2.jar" (from the recent Lucene package) to my project. This
approach works for non-Android projects, but with Android I get an
"InvocationTargetException" (cause: NoClassDefFoundError).

Any ideas?


My test code:

package org.testandroidlucene;

import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.search.Hits;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.RAMDirectory;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;

public class TestAndroidLuceneActivity extends Activity {
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.main);

        try {
                String text = "Hallo";

                        Directory directory = new RAMDirectory();
                        Analyzer analyzer = new StandardAnalyzer();
                        IndexWriter indexWriter = new IndexWriter(directory, 
analyzer,
true);

                        Document doc = new Document();
                        doc.add(new Field("fieldname", text, Field.Store.YES,
Field.Index.TOKENIZED));

                        indexWriter.addDocument(doc);
                        indexWriter.optimize();
                        indexWriter.close();

                        IndexSearcher indexSearcher = new 
IndexSearcher(directory);
                        QueryParser parser = new QueryParser("fieldname", 
analyzer);
                    Query query = parser.parse("H*l?");
                    Hits hits = indexSearcher.search(query);

                    for (int i = 0; i < hits.length(); i++) {
                        Document hitDoc = hits.doc(i);
                        Log.i("TestAndroidLuceneActivity", "Lucene: " +
hitDoc.get("fieldname"));
                    }

                    indexSearcher.close();
                    directory.close();
        } catch (Exception ex) {
        }
    }
}

=============================================================

Log Messages:

DEBUG/dalvikvm(1361): Exception Ljava/lang/ClassNotFoundException;
from PathClassLoader.java:205 not caught locally
DEBUG/dalvikvm(1361): NOTE: loadClass
'org.apache.harmony.luni.internal.locale.ISO4Currencies_en_US'
0x40018950 threw an exception
DEBUG/dalvikvm(1361): Exception Ljava/lang/ClassNotFoundException;
from PathClassLoader.java:205 not caught locally
DEBUG/dalvikvm(1361): NOTE: loadClass
'org.apache.harmony.luni.internal.locale.ISO4Currencies_en' 0x40018950
threw an exception
DEBUG/dalvikvm(1361): Exception Ljava/lang/ClassNotFoundException;
from PathClassLoader.java:205 not caught locally
DEBUG/dalvikvm(1361): NOTE: loadClass
'org.apache.harmony.luni.internal.locale.ISO4CurrenciesToDigits_en_US'
0x40018950 threw an exception
DEBUG/dalvikvm(1361): Exception Ljava/lang/ClassNotFoundException;
from PathClassLoader.java:205 not caught locally
DEBUG/dalvikvm(1361): NOTE: loadClass
'org.apache.harmony.luni.internal.locale.ISO4CurrenciesToDigits_en'
0x40018950 threw an exception
DEBUG/dalvikvm(1361): Exception Ljava/lang/ClassNotFoundException;
from PathClassLoader.java:205 not caught locally
DEBUG/dalvikvm(1361): NOTE: loadClass 'java.rmi.Remote' 0x400acd40
threw an exception
WARN/dalvikvm(1361): Failed resolving Lorg/apache/lucene/search/
Searchable; interface 379 'Ljava/rmi/Remote;'
WARN/dalvikvm(1361): Link of class 'Lorg/apache/lucene/search/
Searchable;' failed
DEBUG/dalvikvm(1361): Exception Ljava/lang/ClassNotFoundException;
from PathClassLoader.java:205 not caught locally
DEBUG/dalvikvm(1361): NOTE: loadClass
'org.apache.lucene.search.Searchable' 0x400acd40 threw an exception
WARN/dalvikvm(1361): Failed resolving Lorg/apache/lucene/search/
Searcher; interface 293 'Lorg/apache/lucene/search/Searchable;'
WARN/dalvikvm(1361): Link of class 'Lorg/apache/lucene/search/
Searcher;' failed
DEBUG/dalvikvm(1361): Exception Ljava/lang/ClassNotFoundException;
from PathClassLoader.java:205 not caught locally
DEBUG/dalvikvm(1361): NOTE: loadClass
'org.apache.lucene.search.Searcher' 0x400acd40 threw an exception
WARN/dalvikvm(1361): Link of class 'Lorg/apache/lucene/search/
IndexSearcher;' failed
DEBUG/dalvikvm(1361): Exception Ljava/lang/ClassNotFoundException;
from PathClassLoader.java:205 not caught locally
DEBUG/dalvikvm(1361): NOTE: loadClass
'org.apache.lucene.search.IndexSearcher' 0x400acd40 threw an exception
DEBUG/dalvikvm(1361): Exception Ljava/lang/NoClassDefFoundError; from
TestAndroidLuceneActivity.java:40 not caught locally
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
Announcing the new M5 SDK!
http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-now-available.html
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to