sbt:对象应用程序不是包的成员
我从 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
感谢 Yifan Yu 在 Google 网上论坛中的回复,这似乎是 sbt Android 插件 中的一个错误。感谢 Jan Berkel 修复了此版本中的错误。
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.
好吧,你没有准确地说出你做了什么(“添加一些 Java 源代码”?怎么样?剪切和粘贴代码?哪个代码?在哪里?什么?),这使得很难给出一个好的答案。不过,从错误信息来看,解释其实很简单。
当您执行“import android.app.Activity”时,它会出现错误。这可能就是您所说的 Java 源代码吗?嗯,我不知道。但我知道您已经导入或位于包
com.mydomain.myproject.android
中,因为消息中是这么说的。换句话说,您有以下其中一项:在其他导入之前。这意味着以下两行是等效的:
这可能不是您想要的。您希望 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:before the other import. What that means is that the following two lines will be equivalent:
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:Or you can just not have a package named
android
in your project.