Android 找不到方法 XXX,从方法 YYY 引用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2349244/
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
Could not find method XXX, referenced from method YYY
提问by alex2k8
I have two android projects, ProjA requires ProjB (in Eclipse Properties > Java Build Path > Projects > Add > ProjB). Every thing compiles ok in Eclipse, but when I run ProjA I get an error:
我有两个 android 项目,ProjA 需要 ProjB(在 Eclipse 属性 > Java 构建路径 > 项目 > 添加 > ProjB)。在 Eclipse 中一切都可以正常编译,但是当我运行 ProjA 时出现错误:
Could not find method XXX, referenced from method YYY.
找不到方法 XXX,从方法 YYY 引用。
Where XXX - is the method from ProjB.
其中 XXX - 是来自 ProjB 的方法。
How can I fix the settings?
如何修复设置?
回答by Ika
I have a similar problem when using external jar (in my case openCSV). The reason I had a problem was due to a change in ADT 17 (or above). What I needed to do to resolve the problem was
使用外部 jar(在我的情况下为 openCSV)时,我遇到了类似的问题。我遇到问题的原因是 ADT 17(或更高版本)发生了变化。我需要做的是解决这个问题
- In Eclipse go to Properties -> Java build path -> Order and export.
- Mark my jar.
- Move jar to top of the list.
- 在 Eclipse 中,转到 Properties -> Java build path -> Order and export。
- 标记我的罐子。
- 将 jar 移至列表顶部。
The solution was found in the following pagewhich reference to a very good article.
回答by Satish
Importing Class from External Jar, Androidyou can try the above link.. I suggest taking care of this "android only support 1.6 and not 1.7" in your library jar
从外部 Jar 导入类,Android你可以试试上面的链接。我建议在你的库 jar 中处理这个“android 只支持 1.6 而不是 1.7”
回答by CommonsWare
Combine the two projects into one.
将两个项目合二为一。
Or, have ProjB build a JAR file that ProjA includes.
或者,让 ProjB 构建 ProjA 包含的 JAR 文件。
Or, turn ProjB into a remote Service, with the method in question exposed via AIDL, and have ProjA bind to that service to use the method.
或者,将 ProjB 变成远程服务,通过 AIDL 公开相关方法,并将 ProjA 绑定到该服务以使用该方法。
回答by James Black
You may want to look at your design, if you don't want to go with the answer by CommonsWare.
如果您不想接受 CommonsWare 的答案,您可能需要查看您的设计。
For example, you could call the second project from the first by using Intents, for example.
例如,您可以使用 Intent 从第一个项目调用第二个项目。
If there is code that is common to the two projects then you may want to pull that into a new project where you can include the files directly into both projects, but if the two are supposed to work together there are different ways in Android to allow Activities to call each other, or to pass information, and you may want to look at those.
如果有两个项目共有的代码,那么您可能希望将其拉入一个新项目中,您可以在其中将文件直接包含在两个项目中,但如果两者应该一起工作,则 Android 中有不同的方式允许相互调用或传递信息的活动,您可能需要查看这些。
回答by satur9nine
I've experienced this problem with the new Android Gradle build system, I fixed it by running gradle clean
and then building and installing again. Build systems are complex beasts and Google still has yet to solve the dependency problem perfectly.
我在使用新的 Android Gradle 构建系统时遇到了这个问题,我通过运行gradle clean
然后再次构建和安装来修复它。构建系统是复杂的野兽,谷歌仍未完美解决依赖问题。