Hi Shahzad,
AFAIK you can't create a new array using the Factory.newInstance()
method, but you can initialize items in the array with the method.

Rule[] rule = new Rule[15];
for(int i = 0; i < rule.length; i++){
    rule[i] = Rule.Factory.newInstance();
}
and then a call to rule[0].setId(SomeVal) shouldn't fail with an NPE.

You can also use generics instead of array if thats more convenient.
to do so, just add to -source 1.5 option to scomp when you compile
your schemas.

-jacobd

On Mon, Dec 22, 2008 at 3:28 PM, Qureshi,Shahzad [Ontario]
<shahzad.qure...@ec.gc.ca> wrote:
> Hi all,
>
> I am having problem creating an array using object.Factory.newInstance()
> method. This is what I am trying to do
>
> I've an xml element and xmlbean generated object is called Rule. I need to
> create an array of Rule to use it in xmlbean genereated method
> setRuleArray(Rule[] args)
>
> I can't use Rule[] rule = new Rule[1];
>
> Because when I try to use rule's methods like
>
> Rule[0].setId(1);
>
> I get a NullPointerException
>
> And I don't know how to use the Factory.newInstance() method to create an
> array
>
> Basically I would like to do something like the following
>
> Rule[] ruleArray = something here that creates the rule array;
>
> ruleArray[0].setId(1);
>
> someObj.setRuleArray(ruleArray);
>
> Any suggestions?
>
> Thank you
>
> Shahzad Qureshi
> Systems Analyst/Programmer
> Applications Directorate, CIOB
> Environment Canada
> shahzad.qure...@ec.gc.ca

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@xmlbeans.apache.org
For additional commands, e-mail: user-h...@xmlbeans.apache.org

Reply via email to