1、对象重复定义
问题描述:
D:\workspace\spark\src\main\Scala\WordCount.scala:3:8
WordCount is already defined as object WordCount
object WordCount {
解决参考博客:Error:(21, 8) FlumePushWordCount is already defined as object FlumePushWordCount object FlumePushWor_WSQ(E)的博客-CSDN博客
2、命令行过长
问题描述:
Error running 'wcPerson': Command line is too long. Shorten command line for wcPerson or also for Application default configuration?
解决办法:
第一步:编辑配置
第二步:修改选项
第三步:选中shorten command line
将其中的shorten command line 选项选中
第四步: 选中classpath file
第五步,配置完成
配置完后,点击apply,点击ok,随后运行程序。ok
3、类型不匹配
D:\workspace\spark\src\main\Scala\PairRDD.scala:8:42
value split is not a member of Char
val pRDD = data.flatMap(line => line.split(",")).map(word => (word,1))
解决办法:
错误信息 "value split is not a member of Char" 出现是因为 line
是 Char
类型而不是 String
类型。在 Scala 中,split
方法只适用于 String
类型,而不适用于 Char
类型。 要解决这个问题,你需要确保 data
的类型是 RDD[String]
或在拆分之前将 line
转换为 String
类型。
原来的代码:
val pRDD = data.flatMap(line => line.split(",")).map(word => (word,1))
修改后的代码:
val pRDD = data.flatMap(line => line.toString.split(",")).map(word => (word, 1))