【问题标题】:classifier4j class not found exception on addMatch() method在 addMatch() 方法上找不到分类器4j 类异常
【发布时间】:2023-04-03 06:22:02
【问题描述】:

当我尝试使用来自 classifier4j 包的贝叶斯分类器类时,我有一个奇怪的行为

基本上我的代码是:

String test_string = "some bla bla web designers in here whatever";
SimpleWordsDataSource wds = new SimpleWordsDataSource();
BayesianClassifier classifier = new BayesianClassifier(wds);
wds.addMatch("Web Design")
Double d = classifier.classify(test_string);

我在尝试运行此代码时得到的是:

run:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
    at net.sf.classifier4J.bayesian.WordProbability.calculateProbability(WordProbability.java:167)
    at net.sf.classifier4J.bayesian.WordProbability.setMatchingCount(WordProbability.java:138)
    at net.sf.classifier4J.bayesian.WordProbability.<init>(WordProbability.java:115)
    at net.sf.classifier4J.bayesian.SimpleWordsDataSource.addMatch(SimpleWordsDataSource.java:94)
    at tothego_classifier_test.Main.main(Main.java:44)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    ... 5 more
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)

这很烦人,因为我一直在尝试运行一个简单的 hello-world 测试(如网站的使用部分)。我在 netbeans 6.9 上,并且我已经包含了 classifier4j 0.6 jar 和可选 jar,在我的主类中也有正确的导入语句。 我知道 Nick Lothian 在这里做出了贡献,所以我觉得很好问! 感谢大家的努力

【问题讨论】:

  • 我没有提到:当我运行没有 wds.addmatch() 语句的代码时,它会从头到尾运行

标签: java exception classification


【解决方案1】:

好的,我解决了这个问题,这里我们为大家提供一个快速的方法:

  • http://commons.apache.org/logging/download_logging.cgi点击此链接下载二进制文件
  • 解压刚刚下载的文件
  • 将 commons-logging-xxx.jar、commons-logging-adapters.jar、commons-logging-api.jar 添加到您的 CLASSPATH / 项目库中(我尝试了很多,它似乎只适用于整个 jar包括)
  • 重建并重新运行

希望这有帮助:)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-03-10
    • 2012-05-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-19
    • 1970-01-01
    • 2013-07-16
    相关资源
    最近更新 更多