XML parsing prob

by eyedol » Wed, 03 Dec 2008 12:51:43 GMT


Sponsored Links
 Can't figure out how to achieve this. I was to get the values for the
tag "thumb" it works fine if the "thumb" tag shows once, but if it
increases, I get an exception thrown. Exception
java.lang.IndexOutOfBoundsException: Invalid location 1, size is 1

Sample xml
<response>

<payload>

<jobs>

<job0>

<job>
<jobid>1</jobid>
<jobtitle>The book</jobtitle>

<jobdescription>
An enterprise or desktop gateway that connects data sources to mobile
networks. Intelligent routing can map messages via GSM modems or SMPP
connections to the lowest-cost delivery channel. Routing by service
and content provider is also configurable. Offline versions for off-
net delivery via modems is available.
</jobdescription>
<locationid>1</locationid>
<locationname>Addis</locationname>
<categoryid>2</categoryid>
<categorytitle>White Color</categorytitle>
</job>

<media>

<mediaitem0>
<id>1</id>
<title/>
<type>1</type>
<thumb>1_1_12277.jpg</thumb>
</mediaitem0>

<mediaitem1>
<id>8</id>
<title/>
<type>1</type>
<thumb>1_1_12282.jpg</thumb>
</mediaitem1>
</media>
</job0>
</jobs>
</payload>

<error>
<code>0</code>
<message>No Error</message>
</error>
</response>

The Java code to fetch the values
...
NodeList thumbnails = doc.getElementsByTagName("thumb");

                for (int i=0;i< thumbnails.getLength();i++) {

                        Element thumbnail= (Element) thumbnails.item(i);
                        Job job = jobs.get(i);
                        t +=thumbnail.getFirstChild().getNodeValue()+",";
                        Job.setThumbnail(t);
                }
...

All I want to achieve is get the values for the thumb tag. What am I
doing wrong and how do I achieve that.
--~--~---------~--~----~------------~-------~--~----~



XML parsing prob

by Xavier Mathews » Wed, 03 Dec 2008 13:17:16 GMT


 I Believe This Is In The Archives.





-- 
Xavier A. Mathews
Student/Browser Specialist/Developer/Web-Master
Google Group Client Based Tech Support Specialist
Hazel Crest Illinois
[EMAIL PROTECTED]@[EMAIL PROTECTED]
"Fear of a name, only increases fear of the thing itself."

--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


XML parsing prob

by eyedol » Wed, 03 Dec 2008 15:09:55 GMT


 I have dug this list but didn't come across anything similar to mine.
Could you point me to a thread?




--~--~---------~--~----~------------~-------~--~----~



XML parsing prob

by Mark Murphy » Wed, 03 Dec 2008 21:02:29 GMT


 


<snip>


You didn't indicate where the exception occurred. That would be useful 
information for us folk out here, to better help you out.

Off the cuff, I don't see a problem in your for() loop.

The only thing that seems strange is your thumbnail logic. With String t 
presumably declared well outside the loop, and the use of t+=, you are 
calling a static setThumbnail() function with one thumbnail on the first 
job, two thumbnails on the second job, three thumbnails on the third 
job, etc. So, I'm guessing perhaps the exception is occurring somewhere 
inside setThumbnail(). But that's just a guess.

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com 

Android Training on the Ranch! -- Mar 16-20, 2009
 http://www.bignerdranch.com/schedule.shtml 

--~--~---------~--~----~------------~-------~--~----~



XML parsing prob

by Digestor » Thu, 04 Dec 2008 00:56:36 GMT


 I  guess the problem is in this line:

Job job = jobs.get(i);

I seems to me (according to your xml sample) that there is only one
job. So in the second run of the for-loop the
IndexOutOfBoundsException-Exception occurs.

Good luck

--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. T-Mobile G1 review - Engadget

T-Mobile G1 review

http://www.engadget.com/2008/10/16/t-mobile-g1-review-part-1-hardware/

http://www.engadget.com/2008/10/16/t-mobile-g1-review-part-2-software-and-wrap-up/
--~--~---------~--~----~------------~-------~--~----~

2. ACTION_MEDIA_EJECT Receiver

I'm trying to register a broadcast listener for ACTION_MEDIA_EJECT. I
tried:

        IntentFilter filter = new IntentFilter();
        filter.addAction( Intent.ACTION_MEDIA_EJECT);
        context.registerReceiver( myCardListener, filter);

but the onReceive of the listener does not get called when I eject the
SD card. Most likely I'm missing the scheme or some other intent
filter data.


--~--~---------~--~----~------------~-------~--~----~

3. Which apps will be included in the Android source code release in 4Q2008?

4. how to get a drop down menu of contacts stored in phone

5. When is the App Market Opening?

6. Changing the gravity of titles in Activity themes

7. Printable Documentation