简体   繁体   English

如何在以下代码中解决java.lang.NoClassDefFoundError?

[英]How to resolve java.lang.NoClassDefFoundError in the following code?

I am new to NLP and JAVA. 我是NLP和JAVA的新手。 Recently I started working on language detection and i got a code from How to detect language of user entered text? 最近,我开始进行语言检测,并且从如何检测用户输入的文本的语言中获得了一个代码 . I am using NetBeans 8.2 and copied the following code in it: 我正在使用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" folder, I just download from github( https://github.com/shuyo/language-detection ) and simply given the path in "profileDirectory" “个人资料”文件夹,我只是从github( https://github.com/shuyo/language-detection )下载,并仅在“ profileDirectory”中给出了路径

I am getting the error as: 我得到的错误为:

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\8.2\executor-snippets\run.xml:53: Java returned: 1
BUILD FAILED (total time: 0 seconds)

I added the required jar file into the library also( http://www.java2s.com/Code/Jar/l/Downloadlangdetectjar.htm ) Since I am new to JAVA, I couldn't understand why this error is coming. 我也将所需的jar文件添加到了库中( http://www.java2s.com/Code/Jar/l/Downloadlangdetectjar.htm )由于我是JAVA的新手,所以我不明白为什么会出现此错误。 Can anyone help me to resolve the error and make the code working? 谁能帮助我解决错误并使代码正常工作?

Please add the jsonic-1.2.0.jar and langdetect.jar into the Build path of your NetBeans project. 请将jsonic-1.2.0.jarlangdetect.jar添加到NetBeans项目的Build路径中。 You can find both these Jar's under the lib directory of the GitHub URL which you had provided earlier. 您可以在先前提供的GitHub URL的lib目录下找到这两个Jar。

Post change, you should be able to get the desired output: 发布更改后,您应该能够获得所需的输出:

[ru:0.9999987658571312]
ru

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM