Exception in thread "main" java.lang.NoSuchMethodError: scala.Product.$init$(Lscala/Product;)V

本文解决IDEA工具运行SparkStreaming的WordCount时出现的NoSuchMethodError错误,原因是Scala版本不匹配。通过调整pom.xml中SparkStreaming依赖的Scala版本,使程序正常运行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

使用IDEA工具运行SparkStreaming的WordCount时,运行报错,报错信息如下:

Exception in thread "main" java.lang.NoSuchMethodError: scala.Product.$init$(Lscala/Product;)V
	at org.apache.spark.streaming.Duration.<init>(Duration.scala:22)
	at org.apache.spark.streaming.Seconds$.apply(Duration.scala:90)
	at com.aaa.streaming.WordCount$.main(WordCount.scala:18)
	at com.aaa.streaming.WordCount.main(WordCount.scala)

经查阅资料,参考https://www.cnblogs.com/zengsong-restService/p/10599007.html初步确认原因为:当前idea引入的scala运行环境版本与idea默认的scala版本不一样
查看本项目的Project Structure,点击Global Libraries选项查看,显示版本一致
在这里插入图片描述
打开pom.xml文件,检查Spark对应的Scala版本,发现添加的SparkStreaming依赖的信息如下:

 <dependency>
            <groupId>org.apache.spark</groupId>
            <artifactId>spark-streaming_2.12</artifactId>
            <version>2.4.4</version>
            <scope>compile</scope>
 </dependency>

修改如下:

 <dependency>
            <groupId>org.apache.spark</groupId>
            <artifactId>spark-streaming_2.11</artifactId>
            <version>2.1.1</version>
            <scope>compile</scope>
 </dependency>

待依赖下载完成后运行程序,即可正常运行。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值