Scala 导入不起作用 - 对象 <name>不是包的成员,sbt 在导入中预先添加当前包命名空间 [英] Scala import not working - object <name> is not a member of package, sbt preppends current package namespace in imports

查看:20
本文介绍了Scala 导入不起作用 - 对象 <name>不是包的成员,sbt 在导入中预先添加当前包命名空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试在 Scala 中导入时遇到问题.对象 Database 存在于 com.me.project.database 下,但是当我尝试导入它时:

I have an issue when trying to import in scala. The object Database exists under com.me.project.database but when I try to import it:

import com.me.project.database.Database

我收到错误:

object Database is not a member of package com.me.project.controllers.com.me.project.database

任何想法是什么问题?

编辑:

值得一提的是,导入在com.me.project.controllers包下的Application.scala文件中,我想不通为什么会将导入附加到当前包虽然,奇怪...

It is worth mentioning that the import is in the file Application.scala under the package com.me.project.controllers, I can't figure out why it would append the import to the current package though, weird...

编辑 2:

所以使用:

import _root_.com.me.project.database.Database

如下所述.但是它应该在没有 _root_ 的情况下工作吗?到目前为止的评论似乎表明它应该.

Does work as mentioned below. But should it work without the _root_? The comments so far seem to indicate that it should.

答案:

所以事实证明,我只需要清理项目即可使导入正常工作,同时使用两者:

So it turns out that I just needed to clean the project for the import to work properly, using both:

import _root_.com.me.project.database.Database

import com.me.project.database.Database

是有效的解决方案.Eclipse 刚刚被搞糊涂了.

are valid solutions. Eclipse had just gotten confused.

推荐答案

导入可以是相对的.那是你唯一的进口吗?小心其他进口,如

imports can be relative. Is that the only import you have? be careful with other imports like

导入com.me

最终,这应该会修复它,然后您可以尝试找到更多相关信息:

ultimately, this should fix it, then you can try to find more about it:

import _root_.com.me.project.database.Database

这篇关于Scala 导入不起作用 - 对象 <name>不是包的成员,sbt 在导入中预先添加当前包命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆