我的代码是:
public class StanfordTagger {
public static void main(String[] args)throws IOException, ClassNotFoundException
{
System.out.println("Starting Stanford Part of Speech Tagger");
//get file name with path from user
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter the path and filename to tag: ");
String fileName = keyboard.nextLine();
String line = null;
// FileReader reads text files in the default encoding.
FileReader fileReader =
new FileReader(fileName);
// Always wrap FileReader in BufferedReader.
BufferedReader bufferedReader =
new BufferedReader(fileReader);
String newFileName = fileName.replace(".txt", "POSTagger.txt");
//create a FileWriter using the new path and file
FileWriter fileWriter = new FileWriter(newFileName);
// Always wrap FileWriter in BufferedWriter.
BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
/* creates a StanfordCoreNLP object, with POS tagging, lemmatization, NER, parsing, and coreference resolution
Properties props = new Properties();
props.setProperty("annotators", "tokenize, ssplit, pos, lemma, ner, parse, dcoref");
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);*/
// Initialize the tagger with a model
MaxentTagger tagger = new MaxentTagger(
"G:\\Natural Language Final Project\\taggers\\english-left3words-distsim.tagger");
while((line = bufferedReader.readLine()) != null) {
System.out.println(tagger.tagString(line));
bufferedWriter.write(tagger.tagString(line)+"\n");
}
// Always close files.
bufferedReader.close();
bufferedWriter.flush();
bufferedWriter.close();
}
}
我跑的错误是:
Enter the path and filename to tag: G:\Natural Language Final Project\tasks_1-20_v1-2\en\qa6_yes-no-questions_test.txt
Exception in thread "main" java.lang.UnsupportedClassVersionError: edu/stanford/nlp/tagger/maxent/MaxentTagger : Unsupported major.minor version 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:792)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at StanfordTagger.main(StanfordTagger.java:78)
Java Result: 1
BUILD SUCCESSFUL (total time: 39 seconds)
有谁知道我需要做些什么来解决这个问题?
答案 0 :(得分:0)
您使用较新的JVM。
新的JVM可以支持加载(大多数)旧类版本。较旧的JVM无法加载创建JVM时不存在的类版本。
从类版本(52)开始,您尝试在Java 7或更低版本的JVM上运行在Java 8环境中编译的代码。
答案 1 :(得分:0)
“当JVM尝试加载类并发现类文件版本为 不支持它抛出UnSupportedClassVersionError和它一般 如果使用更高的JDK版本来编译源文件,则会发生 较低的JDK版本用于运行程序。“
确定您使用相同(或次要)Java版本编译代码来运行它。
您正尝试在Java 6(例如)JVM上运行Java 8(例如)编译代码。