sbt:对象应用程序不是包的成员

发布于 2024-12-09 12:42:53 字数 993 浏览 1 评论 0原文

我从 sbt android 插件 成功构建了仅 Scala 的项目模板。接下来,我尝试将一些 Java 源添加到我的项目中,但在 TR.scala 中出现以下错误。 TR.scala 是从 Java 源代码生成的文件。

[info] Compiling 2 Scala sources and 5 Java sources to D:\Workspaces\MyProject\my-project\target\scala-2.9.0-1\classes...
[error] D:\Workspaces\MyProject\my-project\target\src_managed\main\scala\com\mydomain\myproject\TR.scala:2: object app is not a member of package com.mydomain.myproject.android
[error] import android.app.Activity
[error]                ^
[error] D:\Workspaces\MyProject\my-project\target\src_managed\main\scala\com\mydomain\myproject\TR.scala:3: object view is not a member of package com.mydomain.myproject.android
[error] import android.view.View
[error]                ^
[error] two errors found
[error] {file:/D:/Workspaces/MyProject/my-project/}My Project/compile:compile: Compilation failed
[error] Total time: 5 s, completed Oct 12, 2011 11:20:55 AM

I successfully built the Scala-only project template from the sbt android plugin. Next, I tried to add some Java sources to my project and got the following error in TR.scala. TR.scala is a file generated from the Java sources.

[info] Compiling 2 Scala sources and 5 Java sources to D:\Workspaces\MyProject\my-project\target\scala-2.9.0-1\classes...
[error] D:\Workspaces\MyProject\my-project\target\src_managed\main\scala\com\mydomain\myproject\TR.scala:2: object app is not a member of package com.mydomain.myproject.android
[error] import android.app.Activity
[error]                ^
[error] D:\Workspaces\MyProject\my-project\target\src_managed\main\scala\com\mydomain\myproject\TR.scala:3: object view is not a member of package com.mydomain.myproject.android
[error] import android.view.View
[error]                ^
[error] two errors found
[error] {file:/D:/Workspaces/MyProject/my-project/}My Project/compile:compile: Compilation failed
[error] Total time: 5 s, completed Oct 12, 2011 11:20:55 AM

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

最美的太阳 2024-12-16 12:42:53

感谢 Yifan Yu 在 Google 网上论坛中的回复,这似乎是 sbt Android 插件 中的一个错误。感谢 Jan Berkel 修复了此版本中的错误。

您有一个名为 com.mydomain.myproject.android 的包路径,因此
当编译器尝试编译 TR.scala 时,它会让编译器感到困惑
'com.mydomain.myproject',因为它认为 'android.whatever' 作为
相对路径。该插件尝试将 _root_. 添加到 Activity
它生成的源,但它忘记为 TR.scala 这样做。

Thanks to Yifan Yu's response in Google Groups, it appears to be a bug in the sbt Android plugin. Thanks Jan Berkel, for fixing the bug in this release.

You have a package path named com.mydomain.myproject.android, so
it's confusing the compiler when it tries to compile TR.scala in
'com.mydomain.myproject', because it thinks of 'android.whatever' as a
relative path. The plugin tries to prepend _root_. to the Activity
source it generates, but it forgets to do so for TR.scala.

你不是我要的菜∠ 2024-12-16 12:42:53

好吧,你没有准确地说出你做了什么(“添加一些 Java 源代码”?怎么样?剪切和粘贴代码?哪个代码?在哪里?什么?),这使得很难给出一个好的答案。不过,从错误信息来看,解释其实很简单。

当您执行“import android.app.Activity”时,它会出现错误。这可能就是您所说的 Java 源代码吗?嗯,我不知道。但我知道您已经导入或位于包 com.mydomain.myproject.android 中,因为消息中是这么说的。换句话说,您有以下其中一项:

package com.mydomain.myproject.android
import com.mydomain.myproject._
import com.mydomain.myproject.android

其他导入之前。这意味着以下两行是等效的:

import android.app.Activity
import com.mydomain.myproject.android.app.Activity

这可能不是您想要的。您希望 android.app.Activity 成为绝对引用,对吧?嗯,事实并非如此。您可以像这样将其设置为绝对:

import _root_.android.app.Activity

或者您的项目中可以没有名为 android 的包。

Well, you didn't say exactly what you did ("add some Java sources"? how's that? cut&pasted code? which code? where? what?), which makes it hard to give a good answer. However, the explanation is actually simple from the error message.

It gives an error when you do "import android.app.Activity". Might that be the Java sources you spoke of? Well, I don't know. But I know you have either imported or are inside the package com.mydomain.myproject.android, because it says so in the message. In other words, you have one of the following:

package com.mydomain.myproject.android
import com.mydomain.myproject._
import com.mydomain.myproject.android

before the other import. What that means is that the following two lines will be equivalent:

import android.app.Activity
import com.mydomain.myproject.android.app.Activity

Which is probably not what you want. You wanted android.app.Activity to be an absolute reference, right? Well, it is not. You can make it absolute like this:

import _root_.android.app.Activity

Or you can just not have a package named android in your project.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文