Search code examples
javaandroidandroid-studiojarstanford-nlp

Resolve Class file for java.util.function.Function not found


I want to use the Stanford POS-tagger in my android project.

I added the pos-tagger .jar files to my android project in Android Studio:

  • slf4j-api.jar
  • slf4j-simple.jar
  • stanford-postagger-3.6.0.jar

I can import the library correctly:

import edu.stanford.nlp.tagger.maxent.MaxentTagger;

But an error occurs when I use the function tagString:

MaxentTagger tagger = new MaxentTagger("model/english-left3words-distsim.tagger");
String tagged = tagger.tagString("Hello World");//--->>ERROR
Log.i("tags",tagged);

When compiling, I am getting the error:

Error:(34, 31) error: cannot access Function class file for java.util.function.Function not found Error:Execution failed for task

':app:compileDebugJavaWithJavac'. Compilation failed; see the compiler error output for details.

How can I use the stanford pos-tagger in my Android project correctly?


Solution

  • Are you compiling with Java 8? Recent versions of CoreNLP require Java 8; the error you're seeing is likely from the compiler not finding the newly introduced Function class.