Hello everyone,

I'm having a trouble with definition of lybrary. I don't really know if it
is a concept problem, or a implementation problem.

Let me explain:

I have three projects in my eclipse workspace.

1º -> It's a library, with one interface. I marked this project as a library
in eclipse project properties (Properties->Android->Library->Is Library).

   - There's *interface IPlugin* with *execute() *method.

2º -> It's a plugin implementation (PI-Project). This project references to
this library project using eclipse project properties (add a lybrary in
Properties->Android->Library->Add).

   - There's a class* IPluginImplementation implements IPlugin* and have to
   implement execute() method, of course.
   - This definition it's just fine.
   - I execute this project, and there's no problem with that.


3º -> It's a plugin management implementation, that doesn't know how many
plugin implementations there are, but knows what it is the project that have
every definitions of my plugins. This project references to this library
project using eclipse project properties (add a lybrary in
Properties->Android->Library->Add).

So what I do is:

   - Using PathClassLoader, I'm able to test if my plugin implementation
   exists in PI-Project. (The following code executes just fine)

*classLoader = new
PathClassLoader(apkFiles,ClassLoader.getSystemClassLoader());*
*Class<IPlugin> clazz = (Class<IPlugin>)Class.forName(classPath, false,
classLoader);*

when I call the "execute()" method usinf reflection, there's no problem.

*Method mthd=clazz.getMethod("execute",params);
mthd.invoke(cons.newInstance(), (Object[])null);*

But, when  I try to cast my *IPluginImplementation instance* to my
*IPlugin*referenced interface, the log shows
*java.lang.ClassCastException.*

This doesn't work:   *(clazz.newInstance()).execute();*
And this doesn't work:   *IPlugin obj = clazz.newInstance();*

-----------------------------------------------------------------------------------------------------------
So, finally, my question is: why I'm able to load a class that is defined as
IPlugin*
Class<IPlugin> clazz = (Class<IPlugin>)Class.forName(classPath, false,
classLoader);*

but I can't use IPlugin its execute() method?
*(clazz.newInstance()).execute();*

I notices that my interfaces definitions (the one from referecend library
and the other one from clazz object) has differents ID. But why does this
happen? Is not the same reference interface from the library?

I'm testing my applications on my own phone, android 2.1 installed.


Thanks.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to