classcastexception on reading xml node

Mettieledek

New Member
i'll try to read an xml, following a tutorial finded online here http://www.androidhive.info/2011/11/android-xml-parsing-tutorial/\[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 <item> for (int i = 0; i < 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\]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.This is the Logcat\[code\]07-06 18:03:14.561: E/AndroidRuntime(1602): FATAL EXCEPTION: main07-06 18:03:14.561: E/AndroidRuntime(1602): java.lang.ClassCastException: org.apache.harmony.xml.dom.ElementImpl07-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\]This is the .xml file: \[code\]http://www.radioamicizia.com/demo.xml\[/code\]EDIT: I've tried with original example xml file (http://api.androidhive.info/pizza/?format=xml), but at casting of node to element... ERROR!EDIT: \[code\]static final String KEY_ITEM = "item"; // parent nodestatic final String KEY_TITOLO = "name";static final String KEY_ARTISTA = "cost";\[/code\]Any suggestion?
 
Back
Top