commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <craig...@apache.org>
Subject Re: [BeanUtils] Got NullPointerException when get/set in index property of a BasicDynaBean
Date Thu, 13 Mar 2003 20:21:11 GMT


On Thu, 13 Mar 2003 Natalie_Ng@toyota.ca wrote:

> Date: Thu, 13 Mar 2003 13:19:29 -0500
> From: Natalie_Ng@toyota.ca
> Reply-To: Jakarta Commons Users List <commons-user@jakarta.apache.org>
> To: commons-user@jakarta.apache.org
> Subject: [BeanUtils] Got NullPointerException when get/set in index
>     property of a BasicDynaBean
>
> Hi all, I got a NullPointerException when executing dynaBean.set.
>
>         final BasicDynaClass dynaClass = new BasicDynaClass(
>             "myDynaClass", BasicDynaBean.class, new DynaProperty[] {
>                 new DynaProperty( "strArrayProp", String[].class ),
>                 new DynaProperty( "intArrayProp", Integer[].class )
>             } );
>         final BasicDynaBean dynaBean = (BasicDynaBean)
> dynaClass.newInstance();

At this point, you have created the DynaBean, but *not* the properties
themselves.  You'll want to precreate the arrays with some appropriate
number of elements, perhaps by doing this:

  dynaBean.set("strArrayProp", new String[3]);
  dynaBean.set("intArrayProp", new Integer[5]);

>         dynaBean.set( "strArrayProp", 0, "Hello 0" );
>         getLog().trace( "after second set: strArrayProp[0]=" +dynaBean.get
> ( "strArrayProp", 0 ) );
>
> Did I use DynaBean wrong?
> When I look at the BasicDynaBean implementation, looks like only the set
> method for non-indexed property will check the DynaClass property
> definition. I must be missing something.
>
> Thanks.
>

Craig

Mime
View raw message