Note that there are some explanatory texts on larger screens.

plurals
  1. POclasscastexception on reading xml node
    primarykey
    data
    text
    <p>i'll try to read an xml, following a tutorial finded online here <a href="http://www.androidhive.info/2011/11/android-xml-parsing-tutorial/" rel="nofollow">http://www.androidhive.info/2011/11/android-xml-parsing-tutorial/</a></p> <pre><code>public String leggi_palinsesto() { String comodo=""; XMLParser parser = new XMLParser(); String xml = parser.getXmlFromUrl(URL); // getting XML Document doc = parser.getDomElement(xml); // getting DOM element NodeList nl = doc.getElementsByTagName(KEY_ITEM); // looping through all item nodes &lt;item&gt; for (int i = 0; i &lt; nl.getLength(); i++) { //Element e = null; Element e = (Element) nl.item(i); String titolo = parser.getValue(e, KEY_TITOLO); // name child value String artista = parser.getValue(e, KEY_ARTISTA); // cost child value System.out.println(artista+" - "+titolo); comodo=artista+" - "+titolo; } return comodo; } </code></pre> <p>When the debug arrive to <code>Element e = (Element) nl.item(i);</code> return classcastexception error, but I'm sure that's the correct code.</p> <p>This is the Logcat</p> <pre><code>07-06 18:03:14.561: E/AndroidRuntime(1602): FATAL EXCEPTION: main 07-06 18:03:14.561: E/AndroidRuntime(1602): java.lang.ClassCastException: org.apache.harmony.xml.dom.ElementImpl 07-06 18:03:14.561: E/AndroidRuntime(1602): at it.axiomatic.radioamicizia.RadioAmiciziaActivity.leggi_palinsesto(RadioAmiciziaActivity.java:254) 07-06 18:03:14.561: E/AndroidRuntime(1602): at it.axiomatic.radioamicizia.RadioAmiciziaActivity$1$1.run(RadioAmiciziaActivity.java:121) 07-06 18:03:14.561: E/AndroidRuntime(1602): at android.os.Handler.handleCallback(Handler.java:587) 07-06 18:03:14.561: E/AndroidRuntime(1602): at android.os.Handler.dispatchMessage(Handler.java:92) 07-06 18:03:14.561: E/AndroidRuntime(1602): at android.os.Looper.loop(Looper.java:123) 07-06 18:03:14.561: E/AndroidRuntime(1602): at android.app.ActivityThread.main(ActivityThread.java:4627) 07-06 18:03:14.561: E/AndroidRuntime(1602): at java.lang.reflect.Method.invokeNative(Native Method) 07-06 18:03:14.561: E/AndroidRuntime(1602): at java.lang.reflect.Method.invoke(Method.java:521) 07-06 18:03:14.561: E/AndroidRuntime(1602): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 07-06 18:03:14.561: E/AndroidRuntime(1602): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 07-06 18:03:14.561: E/AndroidRuntime(1602): at dalvik.system.NativeStart.main(Native Method) </code></pre> <p>This is the .xml file: </p> <pre><code>http://www.radioamicizia.com/demo.xml </code></pre> <p>EDIT: I've tried with original example xml file (http://api.androidhive.info/pizza/?format=xml), but at casting of node to element... ERROR!</p> <p>EDIT: </p> <pre><code>static final String KEY_ITEM = "item"; // parent node static final String KEY_TITOLO = "name"; static final String KEY_ARTISTA = "cost"; </code></pre> <p>Any suggestion?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload