Java编译器说无法找到符号。为什么?

时间:2016-10-07 01:39:05

标签: java compiler-errors mahout

我遵循了这个:https://mahout.apache.org/users/recommender/userbased-5-minutes.html

和我的代码:

的pom.xml

请注意,我的<groupId>也是org.apche.mahout

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>org.apache.mahout</groupId>
  <artifactId>first</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>first</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.mahout</groupId>
      <artifactId>mahout-mr</artifactId>
      <version>0.9</version>
    </dependency>
  </dependencies>
</project>

SampleRecommender.java

package org.apache.mahout;

public class SampleRecommender
{
    public static void main(String[] args)
    {
        DataModel model = new FileDataModel(new File("dataset.csv"));
        UserSimilarity similarity = new PearsonCorrelationSimilarity(model);
        UserNeighborhood neighborhood = new ThresholdUserNeighborhood(0.1, similarity, model);

        UserBasedRecommender recommender = new GenericUserBasedRecommender(model, neighborhood, similarity);

        List recommendations = recommender.recommend(2, 3);
        for (RecommendedItem recommendation : recommendations)
            System.out.println(recommendation);
    }
}

当我输入mvn compile时,会出现以下错误:

...After downloading some .jar files...

[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ first ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/[username]/Desktop/ferrari_project/mahout-test/first/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ first ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /Users/[username]/Desktop/ferrari_project/mahout-test/first/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /Users/[username]/Desktop/ferrari_project/mahout-test/first/src/main/java/org/apache/mahout/SampleRecommender.java:[7,17] cannot find symbol
  symbol:   class DataModel
  location: class org.apache.mahout.SampleRecommender
[ERROR] /Users/[username]/Desktop/ferrari_project/mahout-test/first/src/main/java/org/apache/mahout/SampleRecommender.java:[7,39] cannot find symbol
  symbol:   class FileDataModel
  location: class org.apache.mahout.SampleRecommender
[ERROR] /Users/[username]/Desktop/ferrari_project/mahout-test/first/src/main/java/org/apache/mahout/SampleRecommender.java:[7,57] cannot find symbol
  symbol:   class File
  location: class org.apache.mahout.SampleRecommender
[ERROR] /Users/[username]/Desktop/ferrari_project/mahout-test/first/src/main/java/org/apache/mahout/SampleRecommender.java:[8,17] cannot find symbol
  symbol:   class UserSimilarity
  location: class org.apache.mahout.SampleRecommender
[ERROR] /Users/[username]/Desktop/ferrari_project/mahout-test/first/src/main/java/org/apache/mahout/SampleRecommender.java:[8,49] cannot find symbol
  symbol:   class PearsonCorrelationSimilarity
  location: class org.apache.mahout.SampleRecommender
[ERROR] /Users/[username]/Desktop/ferrari_project/mahout-test/first/src/main/java/org/apache/mahout/SampleRecommender.java:[9,17] cannot find symbol
  symbol:   class UserNeighborhood
  location: class org.apache.mahout.SampleRecommender
[ERROR] /Users/[username]/Desktop/ferrari_project/mahout-test/first/src/main/java/org/apache/mahout/SampleRecommender.java:[9,53] cannot find symbol
  symbol:   class ThresholdUserNeighborhood
  location: class org.apache.mahout.SampleRecommender
[ERROR] /Users/[username]/Desktop/ferrari_project/mahout-test/first/src/main/java/org/apache/mahout/SampleRecommender.java:[11,17] cannot find symbol
  symbol:   class UserBasedRecommender
  location: class org.apache.mahout.SampleRecommender
[ERROR] /Users/[username]/Desktop/ferrari_project/mahout-test/first/src/main/java/org/apache/mahout/SampleRecommender.java:[11,56] cannot find symbol
  symbol:   class GenericUserBasedRecommender
  location: class org.apache.mahout.SampleRecommender
[ERROR] /Users/[username]/Desktop/ferrari_project/mahout-test/first/src/main/java/org/apache/mahout/SampleRecommender.java:[13,17] cannot find symbol
  symbol:   class List
  location: class org.apache.mahout.SampleRecommender
[ERROR] /Users/[username]/Desktop/ferrari_project/mahout-test/first/src/main/java/org/apache/mahout/SampleRecommender.java:[14,22] cannot find symbol
  symbol:   class RecommendedItem
  location: class org.apache.mahout.SampleRecommender
[INFO] 11 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 22.228 s
[INFO] Finished at: 2016-10-10T09:57:14+09:00
[INFO] Final Memory: 24M/149M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project first: Compilation failure: Compilation failure:
[ERROR] /Users/[username]/Desktop/ferrari_project/mahout-test/first/src/main/java/org/apache/mahout/SampleRecommender.java:[7,17] cannot find symbol
[ERROR] symbol:   class DataModel
[ERROR] location: class org.apache.mahout.SampleRecommender
[ERROR] /Users/[username]/Desktop/ferrari_project/mahout-test/first/src/main/java/org/apache/mahout/SampleRecommender.java:[7,39] cannot find symbol
[ERROR] symbol:   class FileDataModel
[ERROR] location: class org.apache.mahout.SampleRecommender
[ERROR] /Users/[username]/Desktop/ferrari_project/mahout-test/first/src/main/java/org/apache/mahout/SampleRecommender.java:[7,57] cannot find symbol
[ERROR] symbol:   class File
[ERROR] location: class org.apache.mahout.SampleRecommender
[ERROR] /Users/[username]/Desktop/ferrari_project/mahout-test/first/src/main/java/org/apache/mahout/SampleRecommender.java:[8,17] cannot find symbol
[ERROR] symbol:   class UserSimilarity
[ERROR] location: class org.apache.mahout.SampleRecommender
[ERROR] /Users/[username]/Desktop/ferrari_project/mahout-test/first/src/main/java/org/apache/mahout/SampleRecommender.java:[8,49] cannot find symbol
[ERROR] symbol:   class PearsonCorrelationSimilarity
[ERROR] location: class org.apache.mahout.SampleRecommender
[ERROR] /Users/[username]/Desktop/ferrari_project/mahout-test/first/src/main/java/org/apache/mahout/SampleRecommender.java:[9,17] cannot find symbol
[ERROR] symbol:   class UserNeighborhood
[ERROR] location: class org.apache.mahout.SampleRecommender
[ERROR] /Users/[username]/Desktop/ferrari_project/mahout-test/first/src/main/java/org/apache/mahout/SampleRecommender.java:[9,53] cannot find symbol
[ERROR] symbol:   class ThresholdUserNeighborhood
[ERROR] location: class org.apache.mahout.SampleRecommender
[ERROR] /Users/[username]/Desktop/ferrari_project/mahout-test/first/src/main/java/org/apache/mahout/SampleRecommender.java:[11,17] cannot find symbol
[ERROR] symbol:   class UserBasedRecommender


[ERROR] location: class org.apache.mahout.SampleRecommender
[ERROR] /Users/[username]/Desktop/ferrari_project/mahout-test/first/src/main/java/org/apache/mahout/SampleRecommender.java:[11,56] cannot find symbol
[ERROR] symbol:   class GenericUserBasedRecommender
[ERROR] location: class org.apache.mahout.SampleRecommender
[ERROR] /Users/[username]/Desktop/ferrari_project/mahout-test/first/src/main/java/org/apache/mahout/SampleRecommender.java:[13,17] cannot find symbol
[ERROR] symbol:   class List
[ERROR] location: class org.apache.mahout.SampleRecommender
[ERROR] /Users/[username]/Desktop/ferrari_project/mahout-test/first/src/main/java/org/apache/mahout/SampleRecommender.java:[14,22] cannot find symbol
[ERROR] symbol:   class RecommendedItem
[ERROR] location: class org.apache.mahout.SampleRecommender
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

我的代码有什么问题吗?

为什么他们说cannot find symbol

1 个答案:

答案 0 :(得分:0)

您缺少 mahout-core 作为您的依赖项。请在下面添加,它应该可以使用。

<dependency>
    <groupId>org.apache.mahout</groupId>
    <artifactId>mahout-core</artifactId>
    <version>0.9</version>
</dependency>

检查版本兼容性,如果以上操作不起作用,请添加相应的版本。