我已经尝试使用dynaBeans,如下所示
private static Object createMovieBean() throws Exception {
// first create the properties
DynaProperty properties[] = new DynaProperty[] {
new DynaProperty("title", String.class),
new DynaProperty("dateOfRelease", Date.class),
new DynaProperty("keywords", String[].class),
new DynaProperty("genre", Map.class),
new DynaProperty("actors", List.class), };
// next using the properties define the class
DynaClass movieClass = new BasicDynaClass("movie", null, properties);
// now, with the class, create a new instance
DynaBean movieBean = movieClass.newInstance();
// set its properties
movieBean.set("title", "The Italian Job");
movieBean.set("dateOfRelease",
new GregorianCalendar(1969, 0, 1).getTime());
movieBean.set("keywords", new String[] { "Italy", "Bank Robbery" });
Map genre = new HashMap();
genre.put("THR", "Thriller");
movieBean.set("genre", genre);
movieBean.set("genre", "ACT", "Action");
return movieBean;
}
但这会将错误日志显示为
03-31 14:09:48.736: E/Trace(674): error opening trace file: No such file or directory (2)
03-31 14:09:49.355: W/dalvikvm(674): VFY: unable to find class referenced in signature ([Ljava/beans/PropertyDescriptor;)
03-31 14:09:49.365: I/dalvikvm(674): Could not find method java.beans.PropertyDescriptor.getName, referenced from method org.apache.commons.beanutils.BeanUtilsBean.copyProperties
03-31 14:09:49.365: W/dalvikvm(674): VFY: unable to resolve virtual method 4629: Ljava/beans/PropertyDescriptor;.getName ()Ljava/lang/String;
03-31 14:09:49.365: D/dalvikvm(674): VFY: replacing opcode 0x6e at 0x00bf
03-31 14:09:49.365: W/dalvikvm(674): VFY: unable to find class referenced in signature (Ljava/beans/PropertyDescriptor;)
03-31 14:09:49.375: I/dalvikvm(674): Could not find method java.beans.PropertyDescriptor.getPropertyType, referenced from method org.apache.commons.beanutils.BeanUtilsBean.copyProperty
03-31 14:09:49.375: W/dalvikvm(674): VFY: unable to resolve virtual method 4631: Ljava/beans/PropertyDescriptor;.getPropertyType ()Ljava/lang/Class;
03-31 14:09:49.375: D/dalvikvm(674): VFY: replacing opcode 0x6e at 0x01a4
03-31 14:09:49.375: W/dalvikvm(674): VFY: unable to find class referenced in signature ([Ljava/beans/PropertyDescriptor;)
03-31 14:09:49.375: I/dalvikvm(674): Could not find method java.beans.PropertyDescriptor.getName, referenced from method org.apache.commons.beanutils.BeanUtilsBean.describe
03-31 14:09:49.375: W/dalvikvm(674): VFY: unable to resolve virtual method 4629: Ljava/beans/PropertyDescriptor;.getName ()Ljava/lang/String;
03-31 14:09:49.375: D/dalvikvm(674): VFY: replacing opcode 0x6e at 0x006a
03-31 14:09:49.385: W/dalvikvm(674): VFY: unable to find class referenced in signature (Ljava/beans/PropertyDescriptor;)
03-31 14:09:49.395: W/dalvikvm(674): Unable to resolve superclass of Lorg/apache/commons/beanutils/MappedPropertyDescriptor; (649)
03-31 14:09:49.395: W/dalvikvm(674): Link of class 'Lorg/apache/commons/beanutils/MappedPropertyDescriptor;' failed
03-31 14:09:49.395: E/dalvikvm(674): Could not find class 'org.apache.commons.beanutils.MappedPropertyDescriptor', referenced from method org.apache.commons.beanutils.BeanUtilsBean.setProperty
03-31 14:09:49.395: W/dalvikvm(674): VFY: unable to resolve instanceof 861 (Lorg/apache/commons/beanutils/MappedPropertyDescriptor;) in Lorg/apache/commons/beanutils/BeanUtilsBean;
03-31 14:09:49.395: D/dalvikvm(674): VFY: replacing opcode 0x20 at 0x01cc
03-31 14:09:49.475: W/dalvikvm(674): VFY: unable to resolve exception class 647 (Ljava/beans/IntrospectionException;)
03-31 14:09:49.475: W/dalvikvm(674): VFY: unable to find exception handler at addr 0x1b
03-31 14:09:49.475: W/dalvikvm(674): VFY: rejected Lorg/apache/commons/beanutils/PropertyUtilsBean;.fetchIntrospectionData (Ljava/lang/Class;)Lorg/apache/commons/beanutils/BeanIntrospectionData;
03-31 14:09:49.475: W/dalvikvm(674): VFY: rejecting opcode 0x0d at 0x001b
03-31 14:09:49.475: W/dalvikvm(674): VFY: rejected Lorg/apache/commons/beanutils/PropertyUtilsBean;.fetchIntrospectionData (Ljava/lang/Class;)Lorg/apache/commons/beanutils/BeanIntrospectionData;
03-31 14:09:49.475: W/dalvikvm(674): Verifier rejected class Lorg/apache/commons/beanutils/PropertyUtilsBean;
03-31 14:09:49.475: D/AndroidRuntime(674): Shutting down VM
03-31 14:09:49.475: W/dalvikvm(674): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
03-31 14:09:49.485: E/AndroidRuntime(674): FATAL EXCEPTION: main
03-31 14:09:49.485: E/AndroidRuntime(674): java.lang.VerifyError: org/apache/commons/beanutils/PropertyUtilsBean
03-31 14:09:49.485: E/AndroidRuntime(674): at org.apache.commons.beanutils.BeanUtilsBean.<init>(BeanUtilsBean.java:112)
03-31 14:09:49.485: E/AndroidRuntime(674): at org.apache.commons.beanutils.BeanUtilsBean$1.initialValue(BeanUtilsBean.java:63)
03-31 14:09:49.485: E/AndroidRuntime(674): at org.apache.commons.beanutils.BeanUtilsBean$1.initialValue(BeanUtilsBean.java:59)
03-31 14:09:49.485: E/AndroidRuntime(674): at org.apache.commons.beanutils.ContextClassLoaderLocal.get(ContextClassLoaderLocal.java:154)
03-31 14:09:49.485: E/AndroidRuntime(674): at org.apache.commons.beanutils.BeanUtilsBean.getInstance(BeanUtilsBean.java:75)
03-31 14:09:49.485: E/AndroidRuntime(674): at org.apache.commons.beanutils.BeanUtils.getProperty(BeanUtils.java:380)
03-31 14:09:49.485: E/AndroidRuntime(674): at com.test.testjson.MainActivity.onCreate(MainActivity.java:35)
03-31 14:09:49.485: E/AndroidRuntime(674): at android.app.Activity.performCreate(Activity.java:5008)
03-31 14:09:49.485: E/AndroidRuntime(674): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
03-31 14:09:49.485: E/AndroidRuntime(674): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
03-31 14:09:49.485: E/AndroidRuntime(674): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
03-31 14:09:49.485: E/AndroidRuntime(674): at android.app.ActivityThread.access$600(ActivityThread.java:130)
03-31 14:09:49.485: E/AndroidRuntime(674): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
03-31 14:09:49.485: E/AndroidRuntime(674): at android.os.Handler.dispatchMessage(Handler.java:99)
03-31 14:09:49.485: E/AndroidRuntime(674): at android.os.Looper.loop(Looper.java:137)
03-31 14:09:49.485: E/AndroidRuntime(674): at android.app.ActivityThread.main(ActivityThread.java:4745)
03-31 14:09:49.485: E/AndroidRuntime(674): at java.lang.reflect.Method.invokeNative(Native Method)
03-31 14:09:49.485: E/AndroidRuntime(674): at java.lang.reflect.Method.invoke(Method.java:511)
03-31 14:09:49.485: E/AndroidRuntime(674): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
03-31 14:09:49.485: E/AndroidRuntime(674): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
03-31 14:09:49.485: E/AndroidRuntime(674): at dalvik.system.NativeStart.main(Native Method)
03-31 14:14:49.575: I/Process(674): Sending signal. PID: 674 SIG: 9
我尝试通过使用1.6和1.7 jdk编译代码来解决验证异常,但它没有解决它。它也给出了它无法找到类
的错误E/dalvikvm(674): Could not find class 'org.apache.commons.beanutils.MappedPropertyDescriptor', referenced from method org.apache.commons.beanutils.BeanUtilsBean.setProperty
但它在罐子里请帮助。