Re: [Ikvm-developers] System.NullReferenceException while using java bean Introspector with java.la
Brought to you by:
jfrijters
From: Jeroen F. <je...@su...> - 2009-03-22 17:54:32
|
If you get a System.NullReferenceException on "setMethod.invoke(wekaInstance, values);", your either running into a bug in IKVM's reflection or setMethod is null. Are you sure the property is writeable? If setMethod isn't null, can you build a repro (as small as possible) and send it to me (off list)? Regards, Jeroen > -----Original Message----- > From: abiratsis [mailto:ale...@gm...] > Sent: Sunday, March 22, 2009 11:14 > To: ikv...@li... > Subject: [Ikvm-developers] System.NullReferenceException while using > java bean Introspector with java.lang.string data type > > > 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().toStr > ing()); > 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).ToStr > ing(new > CultureInfo("en-US"))); > break; > case "System.Single": > values[0] = > java.lang.Float.valueOf(Convert.ToSingle(foundOption.ParamValue).ToStri > ng(new > CultureInfo("en-US"))); > break; > case "System.Float": > values[0] = > java.lang.Float.valueOf(Convert.ToSingle(foundOption.ParamValue).ToStri > ng(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. > > > ----------------------------------------------------------------------- > ------- > Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are > powering Web 2.0 with engaging, cross-platform capabilities. Quickly > and easily build your RIAs with Flex Builder, the Eclipse(TM)based > development software that enables intelligent coding and step-through > debugging. > Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com > _______________________________________________ > Ikvm-developers mailing list > Ikv...@li... > https://lists.sourceforge.net/lists/listinfo/ikvm-developers |