Bunny Rabbit
Bunny Rabbit

Reputation: 8411

How to make sense of this scala stacktrace?

The following line results in an error in scala, I know that I am missing a argument in the split method. ≈

scala> "i am learning scala".split()

But I am not able to make sense of the stack trace generated due to this error.

<console>:25: error: overloaded method value split with alternatives:
  (x$1: String)Array[String] <and>
  (x$1: String,x$2: Int)Array[String]
 cannot be applied to ()
       "i am learning scala".split()

Can someone explain the above stack trace to me and how I can relate it to a missing argument?

Upvotes: 1

Views: 186

Answers (2)

C4stor
C4stor

Reputation: 8036

The whole error message decomposes as such :

"Subject" :

overloaded method value split with alternatives:
  (x$1: String)Array[String] <and>
  (x$1: String,x$2: Int)Array[String]

"Verb" :

cannot be applied to ()

"Object":

 "i am learning scala".split()

So the whole first part is the subject, aka a description of what is concerned by the error. This subject is indeed the overloaded method value split followed by a reminder of the different valid signatures for this mehod. Don't search for what you did wrong here, it's only a description of the object concerned by the error ! (a quite verbose one, but still).

The verb gives you the problem, it "cannot be applied".

The object gives you the why : you called it with no arguments, and this doesn't match any of the valid signatures which you were reminded of in the "Subject" part.

Upvotes: 6

geek94
geek94

Reputation: 473

split method always need a delimiter, regex etc. as parameter. ex:

"i am learning scala".split(" ")

this will split the above string on SPACE " " output:

Array[String] = Array("i","am","learning","scala")

And about the stacktrace, compiler is telling you to pass parameters to split method.

Upvotes: 0

Related Questions