I am trying to load an xml file using scala-xml_2.12-1.0.6.jar but it gives me NullPointerEexception while loading
Following is my line of code to load xml
import scala.xml.XML
val xml = XML.loadFile("sample.xml")
I have decompiled this jar and is method is present in that jar but for some reasons it is unable to find it in code.
I have Scala 2.13.1 on my system but for this project I am using scala 2.12.1 and it is mentioned in mu built.sbt
scalaVersion := "2.12.1"
I have following dependency in my built.sbt for this xml package
libraryDependencies += "org.scala-lang.modules" %% "scala-xml" % "1.0.6"
If I copy and paste the same code to Scala interactive shell( scala 2.13.1) I get following error
import scala.xml.XML
^
error: object xml is not a member of package scala
did you mean Nil?
Can anyone please identify what am i doing wrong?
Thanks in advance.
I'm not sure how you are loading up the Scala REPL, but as mentioned in "How to use third party libraries with Scala REPL?", you should be launching the the REPL from SBT with
sbt console. Your.sbtfiles will also need to be in scope.The Scala REPL independently does not deal with
.sbtfiles. They are 2 different tools.Alternatively you could also install Ammonite-REPL which supports Magic Imports. You will be able to import Maven dependencies with
import $ivy.Scala 2.12 comes with
scala-xmland you can remove that dependency as long as you run REPL withsbt consoleand not your native Scala REPL which is already @ Scala 2.13. Otherwise you can also switch to Scala 2.13 for your SBT project.