I've done some modifications to my code and eclipse don't find any
error but the emulator force my application to quit:
java class:
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import android.app.ListActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
public class Xml extends ListActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
ArrayList<String> array_list = null;
try {
array_list = renvoi_liste_recette_xml();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(this,
R.layout.liste,array_list));
}
@SuppressWarnings("unchecked")
public ArrayList<String> renvoi_liste_recette_xml() throws Exception
{
ArrayList<String> aTableRetour = new ArrayList<String>();
URL myURL = new URL("http://benji.roullet.free.fr/testXml.xml");
DocumentBuilderFactory fabrique = DocumentBuilderFactory.newInstance
();
DocumentBuilder constructeur = fabrique.newDocumentBuilder();
Document document = constructeur.parse(myURL.openStream());
Element racine = document.getDocumentElement();
NodeList liste = racine.getElementsByTagName("Contact");
for(int i=0; i<liste.getLength(); i++){
ArrayList<String> aTableauTmp = new ArrayList<String>();
Element E1= (Element) liste.item(i);
aTableauTmp.addAll((Collection<? extends String>)
E1.getElementsByTagName("nom"));
aTableRetour.addAll(aTableauTmp);
}
return aTableRetour;
}
}
Xml file:
<?xml version="1.0" encoding="utf-8"?>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/text">
</TextView>
Do you see anythings wrong ?
On 9 sep, 19:02, "Yusuf Saib (T-Mobile USA)" <[email protected]>
wrote:
> I'm not sure how you want todisplaya list of lists. For that you
> might want some kind of tree widget, not a list view. But if you want
> todisplaya list of string, use setAdapter():
>
> list.setAdapter(new ArrayAdapter<String>(this,
> android.R.layout.list_item, array_list));
>
> Does that answer your question or did you have something else in mind?
>
> Yusuf Saib
> Android
> ·T· · ·Mobile· stick together
> The views, opinions and statements in this email are those of the
> author solely in their individual capacity, and do not necessarily
> represent those of T-Mobile USA, Inc.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---