如何追溯这个编译错误?

发布于 2024-11-14 17:25:55 字数 2072 浏览 4 评论 0原文

我正在通过从书中复制的示例开始学习使用 mahout。然而,Eclipse 编译器给了我以下消息:

> Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
    at org.apache.mahout.cf.taste.impl.model.file.FileDataModel.<clinit>(FileDataModel.java:119)
    at mia.recommender.ch02.RecommenderIntro.main(RecommenderIntro.java:18)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
    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:307)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
    ... 2 more

在我看来,问题来自 FileDataModel.java,它属于这个库本身。如何回溯或者分析这个错误。

示例代码如下,完全是从书上抄来的。造成麻烦的线路是

DataModel model = new FileDataModel(new File("intro.csv")); 


import org.apache.mahout.cf.taste.impl.model.file.*;
import org.apache.mahout.cf.taste.impl.neighborhood.*;
import org.apache.mahout.cf.taste.impl.recommender.*;
import org.apache.mahout.cf.taste.impl.similarity.*;
import org.apache.mahout.cf.taste.model.*;
import org.apache.mahout.cf.taste.neighborhood.*;
import org.apache.mahout.cf.taste.recommender.*;
import org.apache.mahout.cf.taste.similarity.*;
import java.io.*;
import java.util.*;
class RecommenderIntro {
  public static void main(String[] args) throws Exception {


    DataModel model = new FileDataModel(new File("intro.csv")); 
    UserSimilarity similarity = new PearsonCorrelationSimilarity(model);
    UserNeighborhood neighborhood =
      new NearestNUserNeighborhood(2, similarity, model);
    Recommender recommender = new GenericUserBasedRecommender(
        model, neighborhood, similarity); 
    List<RecommendedItem> recommendations =
        recommender.recommend(1, 1); 
    for (RecommendedItem recommendation : recommendations) {
      System.out.println(recommendation);
    }
  }
}

I am learning to use mahout by starting with a example copied from the book. However, the eclipse compiler gives me the following message:

> Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
    at org.apache.mahout.cf.taste.impl.model.file.FileDataModel.<clinit>(FileDataModel.java:119)
    at mia.recommender.ch02.RecommenderIntro.main(RecommenderIntro.java:18)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
    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:307)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
    ... 2 more

It seems to me that the the problem comes from FileDataModel.java, which belongs to this libary itself. How to trace back or analyze this error.

The example code is given as follows, which exactly is the one copied from the book. The line causing the trouble is

DataModel model = new FileDataModel(new File("intro.csv")); 


import org.apache.mahout.cf.taste.impl.model.file.*;
import org.apache.mahout.cf.taste.impl.neighborhood.*;
import org.apache.mahout.cf.taste.impl.recommender.*;
import org.apache.mahout.cf.taste.impl.similarity.*;
import org.apache.mahout.cf.taste.model.*;
import org.apache.mahout.cf.taste.neighborhood.*;
import org.apache.mahout.cf.taste.recommender.*;
import org.apache.mahout.cf.taste.similarity.*;
import java.io.*;
import java.util.*;
class RecommenderIntro {
  public static void main(String[] args) throws Exception {


    DataModel model = new FileDataModel(new File("intro.csv")); 
    UserSimilarity similarity = new PearsonCorrelationSimilarity(model);
    UserNeighborhood neighborhood =
      new NearestNUserNeighborhood(2, similarity, model);
    Recommender recommender = new GenericUserBasedRecommender(
        model, neighborhood, similarity); 
    List<RecommendedItem> recommendations =
        recommender.recommend(1, 1); 
    for (RecommendedItem recommendation : recommendations) {
      System.out.println(recommendation);
    }
  }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谜兔 2024-11-21 17:25:56

看起来 SLF4J 依赖项未安装/在类路径上: slf4j-api.jar

请参阅: http://www.slf4j .org/

It looks like the SLF4J dependency is not installed/on the classpath: slf4j-api.jar

See: http://www.slf4j.org/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文