当前位置:编程学习 > wap >>

java/android 反射技术的使用

直接上问题吧,最近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 楼 zzt369880281 的回复:
你的插件项目,接收这个对象的时候的代码呢?发一下看看

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的方法 --------------------编程问答-------------------- 貌似这个帖子有一个答案 http://bbs.csdn.net/topics/390458778?page=1#post-395639700
补充:移动开发 ,  Android
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,