3

我已经使用 Maven 设置了 Scala 项目。但是它不能编译。我收到一些奇怪的错误,比如缺少一些非常基本的东西。他们之中有一些是:

[ERROR] /home/victor/Work/Projects/Own/Scraper/src/main/scala/me/crawler/Node.scala:17: error: not found: type Map
[INFO]   var attributes: Map[String, String] = null
[INFO]                   ^
[ERROR] /home/victor/Work/Projects/Own/Scraper/src/main/scala/me/crawler/CompanySiteEmailCrawlerController.scala:137: error: not found: type Set
[INFO]   private def addEmailToCompanyList(harvestedRecordsCompanyList: List[Company], company: Company, emailSet: Set[String],[INFO]                                                                                                             ^
[ERROR] /home/victor/Work/Projects/Own/Scraper/src/main/scala/me/crawler/CompanySiteEmailCrawlerController.scala:186: error: value toInt is not a member of String
[INFO]       lineFrom = args(3).toInt
[INFO]                          ^
[ERROR] /home/victor/Work/Projects/Own/Scraper/src/main/scala/me/crawler/crawler4j/Crawler4jAdaptee.scala:25: error: not found: value classOf
[INFO]   private val log: Logger = Logger.getLogger(classOf[Crawler4jAdaptee])
[INFO]                                              ^
[ERROR] /home/victor/Work/Projects/Own/Scraper/src/main/scala/me/crawler/crawler4j/Crawler4jAdaptee.scala:126: error: not found: type Map
[INFO]       val attributesMap: Map[String, String] = attributes.map(a => (a.getKey, a.getValue)).toMap
[INFO]                          ^

因此MapSet集合不是 fount 并且toInt方法不适用于字符串。在我的pom.xml我有:

<dependencies>
    <dependency>
        <groupId>org.scala-lang</groupId>
        <artifactId>scala-library</artifactId>
        <version>2.10.2</version>
    </dependency>
</dependencies>

<build>
    <sourceDirectory>src/main/scala</sourceDirectory>
    <plugins>
        <plugin>
            <groupId>org.scala-tools</groupId>
            <artifactId>maven-scala-plugin</artifactId>
            <version>2.15.2</version>
            <executions>
                <execution>
                    <goals>
                        <goal>compile</goal>
                        <goal>testCompile</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

<repositories>
    <repository>
        <id>scala</id>
        <name>Scala Tools</name>
        <url>http://scala-tools.org/repo-releases/</url>
        <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
</repositories>
<pluginRepositories>
    <pluginRepository>
        <id>scala</id>
        <name>Scala Tools</name>
        <url>http://scala-tools.org/repo-releases/</url>
        <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </pluginRepository>
</pluginRepositories>

我在 Idea 中运行它时遇到的相同错误,虽然 IDE 不会抱怨代码,但只有编译器会抱怨。我对 Scala 很陌生。你能帮帮我吗?

4

1 回答 1

1

导入scala.collection.immutable解决了集合的问题,对于这个classOf问题我找到了解决方法 -getClass改为使用。toInt问题仍未解决。不过有一个解决方法 - 使用该定义中的确切代码:java.lang.Integer.parseInt. 我有一种感觉,这也是进口的问题。

于 2013-07-11T19:40:12.063 回答