Refering from one android project to another Eclipse

别说谁变了你拦得住时间么 提交于 2019-12-24 20:39:24

问题


I've tried this for 2 hours now and I dont seem to get it to work. I want to build a framework for my application, in another project. First of I'm just trying to reach a class from that other project. The code compiles but fails at runtime, at the line where i instantiate an object from a class from the framework.

05-24 18:04:01.645: E/dalvikvm(16927): Could not find class 'frame.test.Hello', referenced from method moduleLogin.activity.Login.loginClick
05-24 18:04:01.645: W/dalvikvm(16927): VFY: unable to resolve new-instance 190 (Lframe/test/Hello;) in LmoduleLogin/activity/Login;
05-24 18:04:02.715: W/dalvikvm(16927): threadid=1: thread exiting with uncaught exception (group=0x4001e578)
05-24 18:04:02.720: E/AndroidRuntime(16927):    at android.view.View$1.onClick(View.java:2154)
05-24 18:04:02.720: E/AndroidRuntime(16927):    at android.view.View.performClick(View.java:2538)
05-24 18:04:02.720: E/AndroidRuntime(16927):    at android.view.View$PerformClick.run(View.java:9152)
05-24 18:04:02.720: E/AndroidRuntime(16927):    at android.os.Handler.handleCallback(Handler.java:587)
05-24 18:04:02.720: E/AndroidRuntime(16927):    at android.os.Handler.dispatchMessage(Handler.java:92)
05-24 18:04:02.720: E/AndroidRuntime(16927):    at android.os.Looper.loop(Looper.java:130)
05-24 18:04:02.720: E/AndroidRuntime(16927):    at android.app.ActivityThread.main(ActivityThread.java:3691)
05-24 18:04:02.720: E/AndroidRuntime(16927):    at java.lang.reflect.Method.invokeNative(Native Method)
05-24 18:04:02.720: E/AndroidRuntime(16927):    at java.lang.reflect.Method.invoke(Method.java:507)
05-24 18:04:02.720: E/AndroidRuntime(16927):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
05-24 18:04:02.720: E/AndroidRuntime(16927):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
05-24 18:04:02.720: E/AndroidRuntime(16927):    at dalvik.system.NativeStart.main(Native Method)
05-24 18:04:02.720: E/AndroidRuntime(16927): Caused by: java.lang.reflect.InvocationTargetException
05-24 18:04:02.720: E/AndroidRuntime(16927):    at java.lang.reflect.Method.invokeNative(Native Method)
05-24 18:04:02.720: E/AndroidRuntime(16927):    at java.lang.reflect.Method.invoke(Method.java:507)
05-24 18:04:02.720: E/AndroidRuntime(16927):    at android.view.View$1.onClick(View.java:2149)
05-24 18:04:02.720: E/AndroidRuntime(16927):    ... 11 more
05-24 18:04:02.720: E/AndroidRuntime(16927): Caused by: java.lang.NoClassDefFoundError: frame.test.Hello
05-24 18:04:02.720: E/AndroidRuntime(16927):    at moduleLogin.activity.Login.loginClick(Login.java:49)
05-24 18:04:02.720: E/AndroidRuntime(16927):    ... 14 more

I know there is a lot on this topic, but I've have searched for hours without any posts solving this problem. Most of the topics are how to reference to another project. But since my code is compiling it should be referenced?

And does both projects needs to be Android projects? Should the framework project be a library? Thanks for any help!


回答1:


if the library project is an android project , you need to make it a library one by choosing it from the project properties , and then to reference it via the same place but on the project that uses it. don't forget that there are some rules when you use a library project . see my post here for more information.

if the library project is java , its exactly as using other java projects.




回答2:


This is a long shot, but it worked for me (having also spent hours on this, after reading all the same posts you did...)

If you are confident that you have correctly configured the project references, this could be a result of a silent build failure.

In my case, the problem arose due to incompatibilities between the build environments for my two projects. In Project "A", which was pure Java, the following line compiled without error in Project A's build environment:

if ((int) d.get("good")) == 0) {....

It turns out that this was not legal in the (Android) Project "B", which required an object cast:

if ((Integer) d.get("good")) == 0) {....

However, the only indication that I got of the error was the same as what you experienced, a "VFY: Unable to resolve..." error.

I found the error in a painful way: By copying the code from Project "A" into Project "B," finding the errors, and fixing them in Project "A." There is probably a more intelligent way than mine to find such incompatibilities, such as by tweaking the settings in both projects to match exactly.



来源:https://stackoverflow.com/questions/10741287/refering-from-one-android-project-to-another-eclipse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!