对象 xml 不是包 scala 的成员

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24559236/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 06:23:16  来源:igfitidea点击:

object xml is not a member of package scala

xmlscalaimportcompiler-errors

提问by zunior

The following code in the compiler:

编译器中的以下代码:

abstract class query {def get: Unit => scala.xml.Elem}

gives me the error: "object xml is not a member of package scala"

给了我错误:“对象 xml 不是包 scala 的成员”

however when I use scala.xml.Elem in sbt through the command line it works just fine,

但是,当我通过命令行在 sbt 中使用 scala.xml.Elem 时,它工作得很好,

how do I fix this?

我该如何解决?

Thanks in advance

提前致谢

回答by Michael Zajac

Scala-XML has been factored out into a separate libraryas of Scala 2.11, so it is not included in Scala projects by default. To include it in your project via sbt add this dependency:

自 Scala 2.11 起,Scala-XML 已被分解为一个单独的库,因此默认情况下它不包含在 Scala 项目中。要通过 sbt 将其包含在您的项目中,请添加此依赖项:

libraryDependencies += "org.scala-lang.modules" %% "scala-xml" % "1.0.2"

回答by EBM

(This is for Windows at least)

(这至少适用于 Windows)

In Eclipse go to

在 Eclipse 中转到

Project > Properties

项目 > 属性

On the windows that appears (should be on Java Build Path on the left) choose the "libraries" section and click on "Add External JARs".

在出现的窗口(应该在左边的 Java Build Path 上)选择“libraries”部分并点击“Add External JARs”。

Navigate to your installation folder and then to the "lib" folder (usually

导航到您的安装文件夹,然后导航到“lib”文件夹(通常是

C:\Program Files (x86)\scala\lib

C:\Program Files (x86)\scala\lib

or

或者

C:\Program Files\scala\lib

C:\Program Files\scala\lib

)

)

and add

并添加

scala-xml_2.11-1.0.2

scala-xml_2.11-1.0.2

or whatever version you have.

或您拥有的任何版本。

回答by user5698801

Update the dependency

更新依赖

// https://mvnrepository.com/artifact/org.scala-lang.modules/scala-xml_2.12
libraryDependencies += "org.scala-lang.modules" % "scala-xml_2.12" % "1.0.6"

回答by HHH

I have the same error, I tried lots of ways. Finally, I found it is the Java Loading dependencies order issue. If I move it to the last one. it works fine for me.

我有同样的错误,我尝试了很多方法。最后发现是Java加载依赖顺序问题。如果我把它移到最后一个。这对我来说可以。

I modify it in my IntelliJ Idea: cmd-; Project Settings -- Modules -- Dependencies click + in bottom-left -- 2 Library -- From Maven The solution

我在我的 IntelliJ Idea 中修改它: cmd-; 项目设置——模块——依赖项点击左下角的+——2库——来自Maven 解决方案