[Ikvm-developers] System.NullReferenceException while using java bean Introspector with java.lang.s
Brought to you by:
jfrijters
From: abiratsis <ale...@gm...> - 2009-03-22 10:14:05
|
Hello guys, I am using weka libraries with .net via IKVM. The following code sets the properties of a weka java Bean by using Java Bean Introspector. I have a problem with strings though, in the case that the Bean property is of type java.lang.String I am getting a System.NullReference exception while calling method.invoke method. I have also found that it happens only for a specific (revision called) property. Here is my code: public static java.lang.Object BindWekaModuleOptions(WekaModule module, List<WekaModuleParameter> options) { java.lang.Object wekaInstance = module.JavaWekaObjectPntr == null ? GetWekaModuleFromName(module, null): module.JavaWekaObjectPntr; BeanInfo info = Introspector.getBeanInfo(wekaInstance.getClass());//configure Bean Introspector for the given class instance //iterate through Bean properties foreach (PropertyDescriptor descr in info.getPropertyDescriptors()) { Type ctype = WekaModuleParameter.ConvertWekaOptionType(descr.getPropertyType().toString()); if (ctype == null) continue; WekaModuleParameter foundOption = options.Find(mod => mod.Name == descr.getName()); if (foundOption != null) { Method setMethod = descr.getWriteMethod(); object[] values = new object[1]; switch (foundOption.DataType.ToString()) { case "System.Double": values[0] = java.lang.Double.valueOf(Convert.ToDouble(foundOption.ParamValue).ToString(new CultureInfo("en-US"))); break; case "System.Single": values[0] = java.lang.Float.valueOf(Convert.ToSingle(foundOption.ParamValue).ToString(new CultureInfo("en-US"))); break; case "System.Float": values[0] = java.lang.Float.valueOf(Convert.ToSingle(foundOption.ParamValue).ToString(new CultureInfo("en-US"))); break; case "System.Int32": values[0] = java.lang.Integer.valueOf(foundOption.ParamValue.ToString()); break; case "System.Boolean": values[0] = java.lang.Boolean.valueOf(foundOption.ParamValue.ToString()); break; case "System.String": values[0] = java.lang.String.valueOf(foundOption.ParamValue); break; default: values[0] = java.lang.String.valueOf(foundOption.ParamValue); break; } try { setMethod.invoke(wekaInstance, values); } catch (Exception ex) { string msg = ex.Message; } } } return wekaInstance; } Does anyone has face any similar problem guys? Thanx a lot -- View this message in context: http://www.nabble.com/System.NullReferenceException-while-using-java-bean-Introspector-with-java.lang.string-data-type-tp22644670p22644670.html Sent from the IKVM .NET - Dev mailing list archive at Nabble.com. |