直接上问题吧,最近ANDROID的项目要实现插件化开发,看了ANDROID插件化开发的相关文章,知道是使用java反射的机制和共享ANDROID的shareduserid技术来实现。这里我要在主项目公开我的对象(xmppconnection)给插件项目使用,可是使用反射传递此对象时,运行时会报异常,如:
java.lang.IllegalArgumentException: argument 2 should have type org.jivesoftware.smack.XMPPConnection, got org.jivesoftware.smack.XMPPConnection 它说我的参数不合法,请问怎么处理。
因为XMPPConnection 是我的项目的核心对象或接口,我要公共给插件项目使用。public void invoke(Plugin plugin, PluginFeature feature,
PluginFeatureMethod method) throws ClassNotFoundException,
IllegalAccessException, InstantiationException, SecurityException,
NoSuchMethodException, IllegalArgumentException,
InvocationTargetException, NameNotFoundException { Context targetContext = context.createPackageContext(
plugin.getPkgInfo().packageName, Context.CONTEXT_INCLUDE_CODE
| Context.CONTEXT_IGNORE_SECURITY); Class<?> c = targetContext.getClassLoader().loadClass(
feature.getFeatureName());
CustomLog
.e(TAG,
TAG
+ "##invoke(Plugin plugin, PluginFeature feature,PluginFeatureMethod method),feature.getFeatureName():"
+ feature.getFeatureName());

Object pluginActivity = c.newInstance(); Method target;
if (method.needContext()) { target = c.getMethod(method.getMethodName(), new Class[] {
Context.class, XMPPConnection.class });
target.invoke(pluginActivity, new Object[] { context,
this.xmppConnection });
} else {
target = c.getMethod(method.getMethodName());
target.invoke(pluginActivity);
} }Android插件对象Java

解决方案 »

  1.   

    public void showDialog1(Context context, XMPPConnection a) {
    CustomLog.d(TAG, TAG + "##showDialog1(Context context),context:"
    + context + ",a:" + a); // 这里显示一个对话框
    ProgressDialog pgdialog = new ProgressDialog(context);
    pgdialog.setTitle("插件1");
    pgdialog.setMessage("来自插件1的问候");
    pgdialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    pgdialog.setCancelable(true);
    pgdialog.show();
    }
    这个就是对应插件项目下activity的方法
      

  2.   

    貌似这个帖子有一个答案 http://bbs.csdn.net/topics/390458778?page=1#post-395639700