tags:

views:

99

answers:

4

I am following the book "Professional Android Application Development" and trying to code some example. In chapter 5 page 151, the following code throw SAXParseException. Does any one know why?

... Document dom = db.parse(in); ....

I tried other xml files, same exception was thrown.

A: 

Try printing out the full exception stack trace for SAXParseException & post it here.

Jacques René Mesrine
+1  A: 

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();
}
James
A: 

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 java.io.InputStreamReader@43d0c720) 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)

cefobid
Try adding <?xml version="1.0" encoding="UTF-8" ?> to the first line of each of the XML files.
Jacques René Mesrine
+1  A: 

It's network problem.....

cefobid