错误未报告的异常 ClassNotFoundException;必须被抓住或宣布被抛出
error unreported exception ClassNotFoundException; must be caught or declared to be thrown
我正在使用可在此处找到的雪球词干分析器 http://snowball.tartarus.org/
我正在使用这个论坛问题为我自己的项目使用词干提取算法
Is there a java implementation of Porter2 stemmer
我使用给定的 class 并使用之前回答 post
中给出的代码
Class stemClass = Class.forName("org.tartarus.snowball.ext." + lang + "Stemmer");
stemmer = (SnowballProgram) stemClass.newInstance();
stemmer.setCurrent("your_word");
stemmer.stem();
String your_stemmed_word = stemmer.getCurrent();
但是当我开始使用 try catch 语句时,我得到了这个错误
assmt1/invert3.java:339: error: incompatible types: try-with-resources not applicable to variable type
try( Class stemClass = Class.forName("org.tartarus.snowball.ext." +"english"+ "Stemmer");
^
(Class cannot be converted to AutoCloseable)
assmt1/invert3.java:340: error: incompatible types: try-with-resources not applicable to variable type
SnowballStemmer stemmer = (SnowballStemmer) stemClass.newInstance())
^
(SnowballStemmer cannot be converted to AutoCloseable)
2 errors
真的不知道如何解决这个问题
只有实现 AutoCloseable
的 类 才能在 try-with-resources 语句声明中使用。
The try-with-resources
statement is a try statement that declares one
or more resources.
A resource is an object that must be closed after
the program is finished with it. The try-with-resources statement
ensures that each resource is closed at the end of the statement. Any
object that implements java.lang.AutoCloseable
, which includes all
objects which implement java.io.Closeable
, can be used as a resource.
Class
和 SnowballStemmer
不是 AutoCloseable
。将它放在 try 块中:
try {
Class stemClass = Class.forName("org.tartarus.snowball.ext." +"english"+ "Stemmer");
SnowballStemmer stemmer = (SnowballStemmer) stemClass.newInstance();
} catch(Exception e){
//Do Something
} finally {
//Do Something
}
我正在使用可在此处找到的雪球词干分析器 http://snowball.tartarus.org/
我正在使用这个论坛问题为我自己的项目使用词干提取算法
Is there a java implementation of Porter2 stemmer
我使用给定的 class 并使用之前回答 post
中给出的代码Class stemClass = Class.forName("org.tartarus.snowball.ext." + lang + "Stemmer");
stemmer = (SnowballProgram) stemClass.newInstance();
stemmer.setCurrent("your_word");
stemmer.stem();
String your_stemmed_word = stemmer.getCurrent();
但是当我开始使用 try catch 语句时,我得到了这个错误
assmt1/invert3.java:339: error: incompatible types: try-with-resources not applicable to variable type
try( Class stemClass = Class.forName("org.tartarus.snowball.ext." +"english"+ "Stemmer");
^
(Class cannot be converted to AutoCloseable)
assmt1/invert3.java:340: error: incompatible types: try-with-resources not applicable to variable type
SnowballStemmer stemmer = (SnowballStemmer) stemClass.newInstance())
^
(SnowballStemmer cannot be converted to AutoCloseable)
2 errors
真的不知道如何解决这个问题
只有实现 AutoCloseable
的 类 才能在 try-with-resources 语句声明中使用。
The
try-with-resources
statement is a try statement that declares one or more resources. A resource is an object that must be closed after the program is finished with it. The try-with-resources statement ensures that each resource is closed at the end of the statement. Any object that implementsjava.lang.AutoCloseable
, which includes all objects which implementjava.io.Closeable
, can be used as a resource.
Class
和 SnowballStemmer
不是 AutoCloseable
。将它放在 try 块中:
try {
Class stemClass = Class.forName("org.tartarus.snowball.ext." +"english"+ "Stemmer");
SnowballStemmer stemmer = (SnowballStemmer) stemClass.newInstance();
} catch(Exception e){
//Do Something
} finally {
//Do Something
}