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. Error in my application... please help me.. :(

Hi,


I've done one application using Listview Concepts.

In my application, I've radio buttons for Languages. The user selects
any one of the language then I've displayed one list whose items are
"Baby, Google, Eclipse". If the user clicks any one of item then the
web browser will opened with corresponding videos.

If the user clicks any one of video then Download page will come. Once
the user clicks "Download Now" link then it will navigate to next page
with the link " Download Ready".

ERROR : If the user clicks the link "Download Ready" then I got some
error page. Then It goes back to Listview page.

I don't know what I've missed here. I've attached my entire source
code here. Can any one run this & fix the issue.

Expected Output : "Automatically the Video file must be downloaded
within PC under the folder "/res/raw" when the user clicks the link
"Download Ready in web page" and the video will display in the
emulator. "


Can't wait for your answer!!!

Thanks in advance for any reply from you!!!

Thanks Again!!!
Yasmin

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

2. Using Activity.openOptionsMenu()

Hi,

Just wondering how one is supposed to use:

    Activity.openOptionsMenu()

I'm calling it in my Activity, but it has no effect. I was expecting:

    onPrepareOptionsMenu(Menu menu) ;

to be called afterwards, but no luck.

Thanks
--~--~---------~--~----~------------~-------~--~----~

3. Can I simulate the key event on the emulator?

4. The constructor WifiInfo() is not visible

5. Is there a video clip that actually plays on emulator

6. Sending and receiving files via FTP

7. MapActivity - Couldn't get connection factory client