0

I have a String value in a variable for eg ID

XML Like

<DocumentElement><Contact ID="1" Name="Test1" 1/><Contact ID="2" Name="TEST" /></DocumentElement>

i get my id in _s2

i want to add all id in a String Array like EmailArr

i have Done

Count=0;
EmailArr=new String[Count];

                String _s2=event.getAttribute("ID").getValue();

                if(_s2=="" || _s2==null){
                    _s2="N/A";
                }

                if(_s2!=null){
                    EmailArr[Count]=_s2;
                    Count=Count++;
                }

I get Exception java.lang.ArrayIndexOutOfBoundsException

2
  • Post the full code. what is event here? Commented Feb 22, 2013 at 7:17
  • event is the xml which i am parsing i get the correct vale in my _s2 Variable i want to add these values in Array Commented Feb 22, 2013 at 7:19

2 Answers 2

0

You need to create an Array with Xml Values:-

int count=XMlData.getPropertyCount();// Get the XML Data count/ some thing related to get  Count of XMl Details


    EmailArr=new String[Count]; // create Array EmailArr with that Count
4
  • Error becuse u are intialize array with 0 Index, you are trying to add Element for Index 1, thats why exception occurs Commented Feb 22, 2013 at 7:22
  • How to get the property count for the xml like you have written int count=XMlData.getPropertyCount(); Commented Feb 22, 2013 at 7:29
  • Here am using SOAP response form .NEt Web Service, so that I can able to use getPropertyCount() method, If you have XMl Data, there will be Count(), to get the count Properties, Error is becuse you need to create Array using that Count Commented Feb 22, 2013 at 7:31
  • int count=response.getPropertyCount(); for(int i=0;i<count; ++i) { SoapObject p= (SoapObject) response.getProperty(i); listProducts.add(new Contatc(Integer.parseInt(p.getProperty(0).toString()),p.getProperty(1).toString())); } some thing like this we can use to get List<Contact> Commented Feb 22, 2013 at 7:34
0

You should give some initial size to your array :

EmailArr=new String[Count];//where count is number of records
1
  • You can't give zero otherwise array size will be zero. Try with some other values. Commented Feb 22, 2013 at 8:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.