1

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!

Lucas Arrefelt
  • 3,879
  • 5
  • 41
  • 71

2 Answers2

2

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.

Community
  • 1
  • 1
android developer
  • 114,585
  • 152
  • 739
  • 1,270
  • I've tried this approach but on the image, when pressing add no alternatives comes around.. – Lucas Arrefelt May 24 '12 at 17:24
  • you need to set the other project as an android library first, and make sure that both projects are on the same workspace (and of course, that they are both android projects). try to also do project->clean , to rebuild all of your projects. – android developer May 24 '12 at 17:34
  • My framework is now a library and it works great this far! I read from your previous post something about doing something special when extending classes from the library? Why is that needed? And is there a way to compile both projects when compiling one of them? :) Thanks for your help! – Lucas Arrefelt May 24 '12 at 21:05
  • please explain what was the solution so that others could enjoy it too. anyway , about what i wrote about extending classes , suppose you have activities on the libraries , and you wish to extend them . the only way you can go between the new activities is to have a mechanism that is in charge of it . the only class i know of that can do it is the one that extends Application . use it as a singleton to get the intents to the activities that have extended the others. – android developer May 24 '12 at 21:10
  • also , about compiling both projects, that's not needed . eclipse will compile only the things that are truly needed . if you changed something on one project , the other one won't need to compile itself , since nothing has changed there , and vice versa . however , if eclipse didn't notice of a change (by editing outside of eclipse , for example) , a clean and/or refresh is needed . – android developer May 24 '12 at 21:16
  • Yes i will update asap! Yeah i figured, it's just that eclipse IntelliSense(?) doesnt take notice on new code from library if you dont clean it – Lucas Arrefelt May 24 '12 at 21:21
  • IntelliSense is of visual studio . on eclipse it's called "content assist" . anyway , it seems you are a starter on eclipse,java and android . i would suggest to watch a few videos of google io : http://www.google.com/events/io/2011/sessions.html .soon (about 34 days from now) there will be even more videos. also , a tiny tip about eclipse : each time you think you do annoying work (or try on random stuff) , try to use CTRL+1 . it can do wonderful things . this can shorten your writing even more than content assist . try to check eclipse's preferences too.there are plenty. – android developer May 24 '12 at 21:48
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.

Ben G.
  • 156
  • 3