SAXParseException in android

I am following the book "Professional Android Application Development" and trying to implement some examples. In chapter 5 page 151, the following code throws a SAXParseException. Does anyone know why?

Document dom = db.parse(in);

I tried other XML files, same exception was thrown.



Stack trace is like:

01-07 00:23:58.875: WARN/System.err(221): org.xml.sax.SAXParseException: expected: /meta read: head (position:END_TAG @1:87 in [email protected]) 01-07 00:23:58.895: WARN/System.err(221): at org.apache.harmony.xml.parsers.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:151) 01-07 00:23:58.906: WARN/System.err(221): at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:157) 01-07 00:23:58.915: WARN/System.err(221): at com.paad.earthquake.Earthquake.refreshEarthquakes(Earthquake.java:82) 01-07 00:23:58.925: WARN/System.err(221): at com.paad.earthquake.Earthquake.onCreate(Earthquake.java:60) 01-07 00:23:58.936: WARN/System.err(221): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 01-07 00:23:58.936: WARN/System.err(221): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2444) 01-07 00:23:58.946: WARN/System.err(221): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2497) 01-07 00:23:58.955: WARN/System.err(221): at android.app.ActivityThread.access$2200(ActivityThread.java:119) 01-07 00:23:58.966: WARN/System.err(221): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1848) 01-07 00:23:58.976: WARN/System.err(221): at android.os.Handler.dispatchMessage(Handler.java:99) 01-07 00:23:58.987: WARN/System.err(221): at android.os.Looper.loop(Looper.java:123) 01-07 00:23:58.996: WARN/System.err(221): at android.app.ActivityThread.main(ActivityThread.java:4338) 01-07 00:23:58.996: WARN/System.err(221): at java.lang.reflect.Method.invokeNative(Native Method) 01-07 00:23:59.026: WARN/System.err(221): at java.lang.reflect.Method.invoke(Method.java:521) 01-07 00:23:59.040: WARN/System.err(221): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860) 01-07 00:23:59.046: WARN/System.err(221): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 01-07 00:23:59.056: WARN/System.err(221): at dalvik.system.NativeStart.main(Native Method)

--------------Solutions-------------

The parse method throws a SAXParseException in case there were any problems in parsing the XML that would cause the rest of the code not be be able to run, since if the XML is invalid then probably you don't want your code to continue.

The parse method declares that it throws SAXParseException so you must explicitly catch that exception when calling that method, e.g.

try {
Document dom = db.parse(in);
} catch (SAXParseException e) {
e.printStackTrace();
}

Category:xml Time:2010-01-06 Views:0
Tags: xml android

Related post

  • Handling gzipped content on Android 2010-10-03

    I'm trying to parse a file from the web on Android using the DOM method. The code in question is: try { URL url = new URL("https://www.beatport.com/en-US/xml/content/home/detail/1/welcome_to_beatport"); InputSource is = new InputSource(url.openStream

  • Strange build error when building an sdl program for android using libSDL 2011-01-22

    I got my hands on the port of SDL to Android not long ago. So, I tried to compile AlienBlaster using the tips in the readme. I updated the project, deleted the src directory, and made the symbolic link successfully. Then I tried to compile it with th

  • Android 3.0 Starter Pack - XML Verification Error 2011-03-20

    I have recently downloaded the SDK starter pack 'android-sdk_r10-windows' for Android development. I have Windows Vista OS. But now when I am starting the SDK Manager to install the Platform tools i am getting the below erorrs - XML verification fail

  • Eclipse suddenly giving parser exception errors on previously working code - Android, Java 2011-03-22

    I haven't worked on this project in about a week. I've changed nothing at all in the code, but today I open it up and try to launch the Android activity, and Eclipse tells me there are errors: org.xml.sax.SAXParseException: Element type "activity" mu

  • android parsing error on tablet but not emulator 2011-10-24

    I have this exception: org.xml.saxParseException: Unexpected token (position [email protected]:2...) but it is caused only when running my .apk on a tablet pc. The same data when is parsed on the android emulator never causes this exception and works 100%. Any

  • android utf-8 file parsing 2011-10-25

    I have some .xml files that are encoded in UTF-8. But whenever I try to parse them on my tablet (idea pad, lenovo, android 3.1), I get the same error: org.xml.SAXParseException: Unexpected token (position: TEXT @1:2 in [email protected]).

  • Refresh view or activity on android 2011-12-28

    I have 1 activity that receives a json object from the server (database) and every activity called view (TableLayout but in ScrollView) automatically updates. But when I delete the data in the database (from current activity or directly from the data

  • Validate XML against schema on Android using Xerces 2012-04-03

    So, after consulting with this thread that the javax.xml.validation library does not work on Android I had to find another solution. I have tried using the Xerces API and although it seems that it is working fine for a lot of people, I can't get it t

  • Using ItemizedOverlay and OverlayItem In Android Beta 0.9 2008-08-25

    Has anyone managed to use ItemizedOverlays in Android Beta 0.9? I can't get it to work, but I'm not sure if I've done something wrong or if this functionality isn't yet available. I've been trying to use the ItemizedOverlay and OverlayItem classes. T

  • Proxy which requires authentication with Android Emulator 2008-08-26

    Has anybody managed to get the Android Emulator working behind a proxy which requires authentication? I've tried setting the -http-proxy argument to http://DOMAIN/USERNAME:[email protected]:PORT but am having no success. I've tried following the docs to no

  • Is there a multiplatform framework for developing iPhone / Android applications? 2008-08-27

    I am interested in writing applications for the iPhone and the Android platform. I was hoping to find a middleware / framework that abstracted away some of the differences in the APIs and allow me to specify the target platform at build time. Is ther

  • Updating Android Tab Icons 2008-08-31

    I have an activity which has a TabHost containing a set of TabSpecs each with a listview containing the items to be displayed by the tab. When each TabSpec is created, I set an icon to be displayed in the tab header. The TabSpecs are created in this

  • Moving to Android from J2ME 2008-09-15

    Coming from J2ME programming are there any similarities that would make it easy to adapt to Android API. Or is Android API completely different from the J2ME way of programming mobile apps. --------------Solutions------------- Actually the Android AP

  • Is there a way to run Python on Android? 2008-09-19

    I like the Android platform. Actually, with some friends, we even participate in the ADC with the Spoxt project. But Java is not my favourite language at all. We are working on an S60 version and this platform has a nice Python API. Of course there i

  • How well does the Android Phone Emulator reflect the performance? 2008-09-19

    I've been playing around with OpenGL ES development on Android. OpenGL ES applications seem to run slowly in the Emulator on my development machine. Does this reflect likely performance of actual hardware? I'm concerned about spending too much time d

  • Getting started with Android 2008-09-27

    So, I'll be getting my T-Mobile G1 within a month or so, and I'm excited to start developing for it. Has anyone started using it yet? Is there a dev wiki or anything set up for it yet? --------------Solutions------------- Google's android groups This

  • Porting Android's Java VM to the iPhone? 2008-09-29

    Does anyone know of any existing projects that aim to port Android's Java VM over to the iPhone? From what I understand, this wouldn't be too out of reach and would certainly make for some exciting developments. Edit: I should point out that I am awa

  • Does Android WebView need permissions for opening external URLs? 2008-10-13

    I was trying the following example, but with external URLs: http://android-developers.blogspot.com/2008/09/using-webviews.html The example shows how to load an HTML file from assets folder (file:// url) and display it in a WebView. But when I try it

  • Android API for detecting new media from inbuilt camera & mic 2008-10-23

    Is there any elegant way in the Android API for detecting new media when it is written to the device? I’m mainly interested in photos taken by the camera, video taken by the camera and audio recorded from the mic. My current thinking is to periodical

Copyright (C) pcaskme.com, All Rights Reserved.

processed in 0.286 (s). 13 q(s)