You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@xmlbeans.apache.org by "Qureshi,Shahzad [Ontario]" <Sh...@ec.gc.ca> on 2008/12/23 00:28:47 UTC
create an array using Factory.newInstance() method
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.qureshi@ec.gc.ca
RE: create an array using Factory.newInstance() method
Posted by "Qureshi,Shahzad [Ontario]" <Sh...@ec.gc.ca>.
Fantastic, that worked. Thank you Jacob
Shahzad Qureshi
Systems Analyst/Programmer
Applications Directorate, CIOB
Environment Canada
shahzad.qureshi@ec.gc.ca
-----Original Message-----
From: Jacob Danner [mailto:jacob.danner@gmail.com]
Sent: Monday, December 22, 2008 7:36 PM
To: user@xmlbeans.apache.org
Subject: Re: create an array using Factory.newInstance() method
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]
<Sh...@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.qureshi@ec.gc.ca
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org
Re: create an array using Factory.newInstance() method
Posted by Jacob Danner <ja...@gmail.com>.
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]
<Sh...@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.qureshi@ec.gc.ca
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org