java 类型错误的方法未定义
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33655198/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
The method is undefined for the type error
提问by Pete
I just don't get why the following lines won't compile:
我只是不明白为什么以下几行不能编译:
TreebankLanguagePack tlp = new PennTreebankLanguagePack();
tlp.setGenerateOriginalDependencies(true);
It was already working before, but now it throws me a
它以前已经可以工作了,但现在它让我感到
The method setGenerateOriginalDependencies(boolean) is undefined for the type TreebankLanguagePack
未定义 TreebankLanguagePack 类型的 setGenerateOriginalDependencies(boolean) 方法
, although TreebankLanguagePack
is marked as the correct interface.
I removed everything and put this minimal class together, but it still doesn't work.
,虽然TreebankLanguagePack
被标记为正确的界面。我删除了所有内容并将这个最小的类放在一起,但它仍然不起作用。
import java.util.Collection;
import edu.stanford.nlp.ling.Sentence;
import edu.stanford.nlp.parser.lexparser.LexicalizedParser;
import edu.stanford.nlp.trees.GrammaticalStructure;
import edu.stanford.nlp.trees.GrammaticalStructureFactory;
import edu.stanford.nlp.trees.PennTreebankLanguagePack;
import edu.stanford.nlp.trees.Tree;
import edu.stanford.nlp.trees.TreebankLanguagePack;
import edu.stanford.nlp.trees.TypedDependency;
public class TreebankTest {
public void test() {
LexicalizedParser lp = LexicalizedParser.loadModel(
"edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz",
"-maxLength", "80", "-retainTmpSubcategories");
TreebankLanguagePack tlp = new PennTreebankLanguagePack();
tlp.setGenerateOriginalDependencies(true);
GrammaticalStructureFactory gsf = tlp.grammaticalStructureFactory();
String[] sent = { "This", "is", "an", "easy", "sentence", "." };
Tree parse = lp.apply(Sentence.toWordList(sent));
GrammaticalStructure gs = gsf.newGrammaticalStructure(parse);
Collection<TypedDependency> tdl = gs.typedDependenciesCCprocessed();
System.out.println(tdl);
}
}
回答by AlexWien
This is a typical situation of "What you see is NOT what you get" in contrast to the well known WYSIWYG.
与众所周知的 WYSIWYG 相比,这是“所见即所得”的典型情况。
You see the method setGenerateOriginalDependencies(boolean) in your src, but the compiler or build system does not see it.
Typical situations:
If the method is in an external library (jar) then either it is not yet built, or you have forgotten to Refresh (eclipse F5) the project. Or you are looking into the wrong project. Or have not saved the file, etc.
您在 src 中看到 setGenerateOriginalDependencies(boolean) 方法,但编译器或构建系统没有看到它。典型情况:
如果该方法在外部库(jar)中,则它尚未构建,或者您忘记刷新(eclipse F5)项目。或者您正在研究错误的项目。或者没有保存文件等。
Or the method does not exist anymore, a working colleague might have removed it. In eclipse you can click on the jar file that contains the method and check what eclipse sees.
或者该方法不再存在,工作同事可能已将其删除。在 eclipse 中,您可以单击包含该方法的 jar 文件并检查 eclipse 看到的内容。
回答by Firzen
In eclipse check your Java buildpath (check your Java JDK/JRE too!), refresh the project (F5) and do Project>Clean of your project.
在 Eclipse 中检查您的 Java 构建路径(也请检查您的 Java JDK/JRE!),刷新项目(F5)并执行 Project>Clean 您的项目。