Scala“未找到:输入”错误

时间:2015-02-27 01:33:23

标签: scala intellij-idea sbt

我是scala noob,我正在为scala spark程序编写单元测试用例。当我尝试使用sbt test命令运行我的scala单元测试用例时,出现以下错误

BasicACRStatsTest.scala:8: not found: type BasicACRStats

[error]   var basicStats: BasicACRStats = _
[error]                   ^
BasicACRStatsTest.scala:14: not found: type BasicACRStats
[error]     basicStats = new BasicACRStats
[error]                      ^
[error] two errors found
[error] (test:compile) Compilation failed

我正在使用intellij,当我尝试引用类BasicACRStats时,它显示Cannot resolve symbol BasicACRStats,即使我已在正确的包中声明它。

BasicACRStat.scala

 package com.company.analytics
 import org.apache.hadoop.conf.Configuration
 import org.apache.hadoop.fs.{FileSystem, Path}
 import org.apache.hadoop.fs.FileSystem.Statistics
 import org.apache.spark.SparkConf
 import org.apache.spark.SparkContext
 import org.apache.spark.sql.hive.HiveContext
 import scala.collection.mutable.ArrayBuffer
 import collection.mutable


 object BasicACRStats {


   def main(args: Array[String]) {
   // Some code goes here
   }
 }

BasicACRStatsTest.scala

    import com.company.analytics
    import org.scalatest.FunSuite
    import org.scalatest.BeforeAndAfter
    import org.apache.spark.SparkConf
    import org.apache.spark.SparkContext

    class BasicACRStatsTest extends FunSuite with BeforeAndAfter {
      @transient var sc: SparkContext = _
      var basicStats: BasicACRStats = _
      // some code goes here
    }

Simple.sbt

name := "basicACRStats"
version := "1.0"
scalaVersion := "2.10.4"
libraryDependencies += "org.apache.spark" %% "spark-core" % "1.2.0"
libraryDependencies += "org.apache.spark" % "spark-sql_2.10" % "1.1.0"
libraryDependencies += "org.apache.spark" % "spark-hive_2.10" % "1.1.0"
libraryDependencies += "org.scalatest" % "scalatest_2.10" % "1.9.1" % "test"

项目目录结构

projectfoo
  .idea
  src
    main
      scala
        com
          company
            analytics
              BasicACRStats.scala
    test
      scala
        BasicACRStatTest.scala
  target
  simple.sbt

我不确定如何解决此问题,请分享您的想法,如果您需要更多信息,请与我们联系。

1 个答案:

答案 0 :(得分:3)

BasicACRStats似乎是示例代码中的object,而不是class

对象是单例而不是类/类型。我拥有类型,在本例中为BasicACRStats.type,只有一个实例。因为它不是一个类型,调用new BasicACRStats是无效的Scala,也没有尝试将它用作值的类型。

你想要的是宣传BasicACRStats一堂课。这将使您的示例代码的其余部分有意义。