如何解析以下代码中的java.lang.NoClassDefFoundError?
How to resolve java.lang.NoClassDefFoundError in the following code?
我是 NLP 新手 JAVA。最近我开始研究语言检测和
我从 How to detect language of user entered text? 那里得到了一个代码。我正在使用 NetBeans 8.2 并在其中复制了以下代码:
package landslip_langdetect;
import java.util.ArrayList;
import com.cybozu.labs.langdetect.Detector;
import com.cybozu.labs.langdetect.DetectorFactory;
import com.cybozu.labs.langdetect.LangDetectException;
import com.cybozu.labs.langdetect.Language;
public class LanguageCodeDetection {
public void init(String profileDirectory) throws LangDetectException {
DetectorFactory.loadProfile(profileDirectory);
}
public String detect(String text) throws LangDetectException {
Detector detector = DetectorFactory.create();
detector.append(text);
return detector.detect();
}
public ArrayList<Language> detectLangs(String text) throws LangDetectException {
Detector detector = DetectorFactory.create();
detector.append(text);
return detector.getProbabilities();
}
public static void main(String args[]) {
try {
LanguageCodeDetection ld = new LanguageCodeDetection();
String profileDirectory = "C:\Users\user\Documents\NetBeansProjects\LangDetect\profiles\";
ld.init(profileDirectory);
String text = "Кремль россий";
System.out.println(ld.detectLangs(text));
System.out.println(ld.detect(text));
} catch (LangDetectException e) {
}
}
}
"profiles" 文件夹,我只是从 github(https://github.com/shuyo/language-detection) 下载并简单地给出 "profileDirectory"
中的路径
我得到的错误是:
Exception in thread "main" java.lang.NoClassDefFoundError: net/arnx/jsonic/JSONException
at shyjo_langDetect.LanguageCodeDetection_1.init(LanguageCodeDetection_1.java:21)
at shyjo_langDetect.LanguageCodeDetection_1.main(LanguageCodeDetection_1.java:40)
Caused by: java.lang.ClassNotFoundException: net.arnx.jsonic.JSONException
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 2 more
C:\Users\geethu\AppData\Local\NetBeans\Cache.2\executor-snippets\run.xml:53: Java returned: 1
BUILD FAILED (total time: 0 seconds)
我也将需要的jar文件添加到库中(http://www.java2s.com/Code/Jar/l/Downloadlangdetectjar.htm)
由于我是 JAVA 的新手,我无法理解为什么会出现此错误。谁能帮我解决错误并使代码正常工作?
请将 jsonic-1.2.0.jar 和 langdetect.jar 添加到您的 NetBeans 的构建路径中项目。您可以在您之前提供的 GitHub URL 的 lib 目录下找到这两个 Jar。
Post改变,应该可以得到想要的输出:
[ru:0.9999987658571312]
ru
我是 NLP 新手 JAVA。最近我开始研究语言检测和 我从 How to detect language of user entered text? 那里得到了一个代码。我正在使用 NetBeans 8.2 并在其中复制了以下代码:
package landslip_langdetect;
import java.util.ArrayList;
import com.cybozu.labs.langdetect.Detector;
import com.cybozu.labs.langdetect.DetectorFactory;
import com.cybozu.labs.langdetect.LangDetectException;
import com.cybozu.labs.langdetect.Language;
public class LanguageCodeDetection {
public void init(String profileDirectory) throws LangDetectException {
DetectorFactory.loadProfile(profileDirectory);
}
public String detect(String text) throws LangDetectException {
Detector detector = DetectorFactory.create();
detector.append(text);
return detector.detect();
}
public ArrayList<Language> detectLangs(String text) throws LangDetectException {
Detector detector = DetectorFactory.create();
detector.append(text);
return detector.getProbabilities();
}
public static void main(String args[]) {
try {
LanguageCodeDetection ld = new LanguageCodeDetection();
String profileDirectory = "C:\Users\user\Documents\NetBeansProjects\LangDetect\profiles\";
ld.init(profileDirectory);
String text = "Кремль россий";
System.out.println(ld.detectLangs(text));
System.out.println(ld.detect(text));
} catch (LangDetectException e) {
}
}
}
"profiles" 文件夹,我只是从 github(https://github.com/shuyo/language-detection) 下载并简单地给出 "profileDirectory"
中的路径我得到的错误是:
Exception in thread "main" java.lang.NoClassDefFoundError: net/arnx/jsonic/JSONException
at shyjo_langDetect.LanguageCodeDetection_1.init(LanguageCodeDetection_1.java:21)
at shyjo_langDetect.LanguageCodeDetection_1.main(LanguageCodeDetection_1.java:40)
Caused by: java.lang.ClassNotFoundException: net.arnx.jsonic.JSONException
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 2 more
C:\Users\geethu\AppData\Local\NetBeans\Cache.2\executor-snippets\run.xml:53: Java returned: 1
BUILD FAILED (total time: 0 seconds)
我也将需要的jar文件添加到库中(http://www.java2s.com/Code/Jar/l/Downloadlangdetectjar.htm) 由于我是 JAVA 的新手,我无法理解为什么会出现此错误。谁能帮我解决错误并使代码正常工作?
请将 jsonic-1.2.0.jar 和 langdetect.jar 添加到您的 NetBeans 的构建路径中项目。您可以在您之前提供的 GitHub URL 的 lib 目录下找到这两个 Jar。
Post改变,应该可以得到想要的输出:
[ru:0.9999987658571312]
ru