Search code examples
scalaapache-sparkspark-submit

Why can't I put 'Val' in function definition arguments. Error ':' expected but '}' found pops up


I was trying to submit this code using spark submit. I found the following errors. I also would like to know how to do a function call in Scala and how do we start the function definition. I am calling file_reading function and I got the below error.

Here is my my function definition

def file_reading(file: String,val start:Int,val end:Int): Unit = {

Here are the Error I got:

/home/ram/sbt_project/src/main/scala/Scala_sample.scala:19:33: identifier expected but 'val' found.
[error]   def file_reading(file: String,val start:Int,val end:Int): Unit = {
[error]                                 ^
[error] /home/ram/sbt_project/src/main/scala/Scala_sample.scala:28:1: ':' expected but '}' found.
[error] }
[error] ^
[error] two errors found

Solution

  • Please remove val in the method.

     def file_reading(file: String,start:Int,end:Int): Unit = {
    

    Please correct for loop, next you will be getting error here.

    paths ??

    for(each <- file)