max42350 Posted April 21, 2010 Share Posted April 21, 2010 (edited) Bonjour, Mon problème est simple je dispose d'un parseur xml qui marche sans soucis en mode console java classique. Mais dès que je tente de passez le tout sous android rien niet nada je ne comprend pas et c'est pourquoi je vous appel a l'aide. Pour le moment je souhaite juste faire l'affichage du parsage je verrais la formation en liste plus tard mais même là sa bloque. Voici le code : Classe Musique [console] : import java.net.URL; import java.util.ArrayList; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import org.xml.sax.InputSource; import org.xml.sax.XMLReader; public class Test { public static void musique(String[] args){ try{ URL fichier = new URL("http://..../fichier.xml"); SAXParserFactory fabrique = SAXParserFactory.newInstance(); SAXParser parseur = fabrique.newSAXParser(); XMLReader xr = parseur.getXMLReader(); ReglageParseur gestionnaire = new ReglageParseur(); xr.setContentHandler(gestionnaire); xr.parse(new InputSource(fichier.openStream())); ArrayList<?> rss = gestionnaire.getRss(); for(int i = 0; i < rss.size(); i++) System.out.println("Élément à l'index " + i + " = " + rss.get(i)); /*String[] x = (String[]) rss.toArray(new String[rss.size()]); System.out.println(x[1]); String st1 = (String) rss.get(0); String[] tokens = st1.split("#"); System.out.println(tokens[1]);*/ }catch(Exception e){} //ReglageParseur r = new ReglageParseur(); } } Classe Musique [Android] : package com.android.m; import java.net.URL; import java.util.ArrayList; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import org.xml.sax.InputSource; import org.xml.sax.XMLReader; import android.app.Activity; import android.app.ListActivity; import android.os.Bundle; import android.util.Log; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.TextView; public class Musique extends Activity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); TextView textview = new TextView(this); try{ URL fichier = new URL("http://.../fichier.xml"); SAXParserFactory fabrique = SAXParserFactory.newInstance(); SAXParser parseur = fabrique.newSAXParser(); XMLReader xr = parseur.getXMLReader(); ReglageParseur gestionnaire = new ReglageParseur(); xr.setContentHandler(gestionnaire); xr.parse(new InputSource(fichier.openStream())); ArrayList rss = gestionnaire.getRss(); for(int i = 0; i < rss.size(); i++) textview.setText((String) rss.get(i)); }catch(Exception e){ Log.e("Musique", "Exception levée" + e.getMessage()); e.printStackTrace(); } setContentView(textview); } } Classe ReglageParseur : package com.android.m; import java.util.ArrayList; import org.xml.sax.Attributes; import org.xml.sax.SAXException; import org.xml.sax.helpers.DefaultHandler; public class ReglageParseur extends DefaultHandler{ //Result parsing private ArrayList rss; private RetourParseur retour; //Position parse @SuppressWarnings("unused") private boolean inRss, inChannel, inItem, inTitle, inPubdate, inCategory, inEnclosure, inMoreinfo, inLink; //Detection start quote public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException{ if(qName.equals("rss")){ rss = new ArrayList(); inRss = true; } else if(qName.equals("channel")){ inChannel = true; } else if(qName.equals("item")){ retour = new RetourParseur(); inItem = true; } else if(qName.equals("title")){ inTitle = true; } else if(qName.equals("pubdate")){ inPubdate = true; } else if(qName.equals("category")){ inCategory = true; } else if(qName.equals("enclosure")){ try{ String url = attributes.getValue("url"); retour.setEnclosure(url); }catch(Exception e){ throw new SAXException(e);} inEnclosure = true; } else if(qName.equals("moreinfo")){ inMoreinfo = true; } else if(qName.equals("link")){ inLink = true; } } //Detection end quote public void endElement(String uri, String localName, String qName) throws SAXException{ if(qName.equals("rss")){ inRss = false; } else if(qName.equals("channel")){ inChannel = false; } else if(qName.equals("item")){ rss.add(retour); retour = null; inItem = false; } else if(qName.equals("title")){ inTitle = false; } else if(qName.equals("pubdate")){ inPubdate = false; } else if(qName.equals("category")){ inCategory = false; } else if(qName.equals("enclosure")){ inEnclosure = false; } else if(qName.equals("moreinfo")){ inMoreinfo = false; } else if(qName.equals("link")){ inLink = false; } } //Detection characters public void characters(char[] ch, int start, int length) throws SAXException{ String lecture = new String(ch,start,length); if(inTitle){ retour.setTitle(lecture); } else if(inPubdate){ retour.setPubdate(lecture); } else if(inCategory){ retour.setCategory(lecture); } else if(inEnclosure){ retour.setEnclosure(lecture); } else if(inMoreinfo){ retour.setMoreinfo(lecture); } else if(inLink){ retour.setLink(lecture); } } //Start parsing public void startDocument() throws SAXException {} //End parsing public void endDocument() throws SAXException {} public ArrayList getRss() { return rss; } } Classe RetourParseur : package com.android.m; public class RetourParseur { private String title, pubdate, category, enclosure, moreinfo, link; public RetourParseur(){} public String getTitle(){return title;} public String getPubdate(){return pubdate;} public String getCategory(){return category;} public String getEnclosure(){return enclosure;} public String getMoreinfo(){return moreinfo;} public String getLink(){return link;} public void setTitle(String title){this.title = title;} public void setPubdate(String pubdate){this.pubdate = pubdate;} public void setCategory(String category){this.category = category;} public void setEnclosure(String enclosure){this.enclosure = enclosure;} public void setMoreinfo(String moreinfo){this.moreinfo = moreinfo;} public void setLink(String link){this.link = link;} public String toString(){ return this.title+"#"+ this.pubdate+"#"+ this.category+"#"+ this.enclosure+"#"+ this.moreinfo+"#"+ this.link; } } Edited June 1, 2010 by max42350 Quote Link to comment Share on other sites More sharing options...
eden91940 Posted April 21, 2010 Share Posted April 21, 2010 la log ? Quote Link to comment Share on other sites More sharing options...
max42350 Posted April 22, 2010 Author Share Posted April 22, 2010 Je ne met que les erreurs : 04-22 07:12:44.723: ERROR/vold(26): Error opening switch name path '/sys/class/switch/test2' (No such file or directory) 04-22 07:12:44.723: ERROR/vold(26): Error bootstrapping switch '/sys/class/switch/test2' (No such file or directory) 04-22 07:12:44.824: ERROR/vold(26): Error opening switch name path '/sys/class/switch/test' (No such file or directory) 04-22 07:12:44.824: ERROR/vold(26): Error bootstrapping switch '/sys/class/switch/test' (No such file or directory) 04-22 07:13:03.643: ERROR/BatteryService(52): usbOnlinePath not found 04-22 07:13:03.643: ERROR/BatteryService(52): batteryVoltagePath not found 04-22 07:13:03.643: ERROR/BatteryService(52): batteryTemperaturePath not found 04-22 07:13:03.673: ERROR/SurfaceFlinger(52): Couldn't open /sys/power/wait_for_fb_sleep or /sys/power/wait_for_fb_wake 04-22 07:13:12.883: ERROR/EventHub(52): could not get driver version for /dev/input/mouse0, Not a typewriter 04-22 07:13:12.894: ERROR/EventHub(52): could not get driver version for /dev/input/mice, Not a typewriter 04-22 07:13:13.204: ERROR/System(52): Failure starting core service 04-22 07:13:13.204: ERROR/System(52): java.lang.SecurityException 04-22 07:13:13.204: ERROR/System(52): at android.os.BinderProxy.transact(Native Method) 04-22 07:13:13.204: ERROR/System(52): at android.os.ServiceManagerProxy.addService(ServiceManagerNative.java:146) 04-22 07:13:13.204: ERROR/System(52): at android.os.ServiceManager.addService(ServiceManager.java:72) 04-22 07:13:13.204: ERROR/System(52): at com.android.server.ServerThread.run(SystemServer.java:176) 04-22 07:13:13.214: ERROR/AndroidRuntime(52): Crash logging skipped, no checkin service 04-22 07:13:30.793: ERROR/ActivityThread(100): Failed to find provider info for android.server.checkin 04-22 07:13:31.093: ERROR/vold(26): Cannot start volume '/sdcard' (volume is not bound) 04-22 07:13:31.973: ERROR/MediaPlayerService(30): Couldn't open fd for content://settings/system/notification_sound 04-22 07:13:32.043: ERROR/MediaPlayer(52): Unable to to create media player 04-22 07:13:34.423: ERROR/ActivityThread(100): Failed to find provider info for android.server.checkin 04-22 07:13:34.524: ERROR/ActivityThread(100): Failed to find provider info for android.server.checkin 04-22 07:13:41.593: ERROR/AndroidRuntime(127): ERROR: thread attach failed 04-22 07:13:54.454: ERROR/AndroidRuntime(180): ERROR: thread attach failed 04-22 07:13:57.653: ERROR/Musique(219): Exception levee null Quote Link to comment Share on other sites More sharing options...
eden91940 Posted April 24, 2010 Share Posted April 24, 2010 ERROR/Musique(219): Exception levee null c'est quoi ? Quote Link to comment Share on other sites More sharing options...
Pierre87 Posted April 24, 2010 Share Posted April 24, 2010 ça serait bien d'indiquer le pid de ton processus, parce que là ... Quote Link to comment Share on other sites More sharing options...
arnouf Posted April 25, 2010 Share Posted April 25, 2010 Ce ne serait pas ton fichier qui est vide ou null par hasard ? Est-ce que le fichier est atteignable (htaccess...ou un truc du genre qui bloque l'accès au fichier)... Quote Link to comment Share on other sites More sharing options...
popolbx Posted April 25, 2010 Share Posted April 25, 2010 permission de lecture sur SDCARD ? Quote Link to comment Share on other sites More sharing options...
Cyril Mottier Posted April 25, 2010 Share Posted April 25, 2010 Essaie de séparer chaque instructions pouvant lever une exception. En effet, faire un seul et unique bloc "try { } catch (Exception e) { }" ne permet pas vraiment de déceler le problème vu que tu rattrape tout ... Il y a tout de même quelque chose qui me tracasse ... Tu récupère une Exception nulle .. ce qui n'est normalement pas possible. Le e.printStackTrace() devrait donner plus d'informations mais tu ne le fourni pas dans ton log. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.