简体   繁体   中英

Exception in thread "main" java.lang.NoSuchMethodError: 'void scala.util.matching.Regex.<init>(java.lang.String, scala.collection.Seq)'

This error occurs when I try to read .xlsx file as a DataFrame in csv format. Can anyone please help me what is the issue here and how to resolve it ? Below is the code I used,

package Sample

import org.apache.spark.sql{SparkSession, SparkContext}
import org.apache.spark.SparkConf

Object Read extends App {

val conf = new SparkConf()
.setAppName("Excel to DataFrame")
.setMaster("local[*]")

val sc = new SparkContext(conf)
sc.setLogLevel("WARN")


val spark = SparkSession.builder()
.appName("Excel to DataFrame")
.config("spark.master","local")
.getOrCreate()

val inputDF = spark.read
.format("csv")
.option("inferSchema","true")
.option("path","G:\\Sample Input.xlsx")
.load()

inputDF.show()

}

The problem you have encountered is that the scala version is not compatible with the spark you install in your operating system. So you need to reconfigure the scala version of the IDE you use, I will explain to you the solution in IntelliJ IDEA, First, go to File -> Project Structure -> Global Libraries and then click on New Global Library (Alt+Insert) and then Select Scala SDK Then a new window will be popup to you like this : New Global Library the scala version you see is the one that causes the problem to you, it needs to be suitable with the scala you install for spark so just go to the terminal and type spark-shell in the terminal you will see the version of scala you use in Spark :

saprk-shell here back to the New Global Library Window and click Download Select the version you have seen in the spark-shell and click OK . After that refresh Edit the dependency in pom.xml and refresh the project and the problem will be solved.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM