错误:在Eclipse中找不到或加载带有Spark的主类
从Eclipse(scala)运行spark应用程序时遇到问题。但是,我能够从eclipse中运行Scala,没有任何问题;这个问题似乎只出现在spark应用程序中 错误:无法找到或加载主类com.sidSparkScala.ratingsconter*错误:在Eclipse中找不到或加载带有Spark的主类,eclipse,scala,apache-spark,Eclipse,Scala,Apache Spark,从Eclipse(scala)运行spark应用程序时遇到问题。但是,我能够从eclipse中运行Scala,没有任何问题;这个问题似乎只出现在spark应用程序中 错误:无法找到或加载主类com.sidSparkScala.ratingsconter* 您的类未正确编译,否则eclipse可能会找到该类。请检查,是否存在编译错误。您最初创建的包名似乎是com.sidSparkScala.ratingsconter,脚本中提到的包名是com.sundogsoftware.spark(位于顶部)。
您的类未正确编译,否则eclipse可能会找到该类。请检查,是否存在编译错误。您最初创建的包名似乎是
com.sidSparkScala.ratingsconter
,脚本中提到的包名是com.sundogsoftware.spark
(位于顶部)。您所要做的就是将包com.sundogsoftware.spark
替换为com.sidSparkScala.ratingsconter
您必须将包名更改为您的,而不是提供的课程。
我想您应该从外部导入这个scala文件,基于上面的代码,包是com.sundogsoftware.spark,只要将它更改为您的就可以了。您在eclipse ide中将scala特性添加到您的项目中了吗???很抱歉这个天真的问题,但是,
package
语句是否确实丢失了,或者您只是忘记将其粘贴到这里?您是否给出了正确的包名。我猜包名有点不匹配。实际上包名有点不匹配。一旦我给了正确的名字,它就工作得很好。不知道我怎么会忽略了这么一件小事,花了一整天的时间来解决这个问题:)。很好。非常感谢你。
package com.sundogsoftware.spark
import org.apache.spark._
import org.apache.spark.SparkContext._
import org.apache.log4j._
/**
* Count up how many of each star rating exists in the MovieLens
* 100K data set.
*/
object RatingsCounter {
/** Our main function where the action happens */
def main(args: Array[String]) {
// Set the log level to only print errors
Logger.getLogger("org").setLevel(Level.ERROR)
// Create a SparkContext using every core of the local machine, named RatingsCounter
val sc = new SparkContext("local[*]", "RatingsCounter")
// Load up each line of the ratings data into an RDD
val lines = sc.textFile("../ml-100k/u.data")
// Convert each line to a string, split it out by tabs, and extract the third field.
// (The file format is userID, movieID, rating, timestamp)
val ratings = lines.map(x => x.toString().split("\t")(2))
// Count up how many times each value (rating) occurs
val results = ratings.countByValue()
// Sort the resulting map of (rating, count) tuples
val sortedResults = results.toSeq.sortBy(_._1)
// Print each result on its own line.
sortedResults.foreach(println)
}
}