Salut tout le monde
j'essaie de parser un fichier xml stocké sur un serveur web pour ajouter des marker sur une google map.
tout marche (google map, menus, ajout d'un marker fixe...) sauf bien sur l'extraction des données.
J'ai testé le même code sur une mini appli et il tourne nickel mais là ca plante...z'auriez une idée? voici le code qui fait planter
c'est dans cette partie que ca plante car quand je la met en commentaire tout fonctionne et comme vous pouvez le constater je ne fais que générer un toast pour bien voir si mes données sont là...
MainCopainsActivity.class
potalos.java
potalos = Monxmlhandler.potalos;
name = new String[potalos.getName().size()];
lat = new double[potalos.getName().size()];
lng = new double[potalos.getName().size()];
heure = new String[potalos.getName().size()];
litrage = new String[potalos.getName().size()];
voile = new String[potalos.getName().size()];
for (int i = 0; i < potalos.getName().size(); i++) {
final StringBuilder msg = new StringBuilder("\n");
msg.append(""+potalos.getName().get(i));
msg.append("|"+potalos.getlat().get(i));
msg.append("|"+potalos.getlng().get(i));
msg.append("|"+potalos.getheure().get(i));
msg.append("|"+potalos.getlitrage().get(i));
msg.append("|"+potalos.getvoile().get(i));
Toast.makeText(this, msg, Toast.LENGTH_LONG).show();
}
et mon handler
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49 import java.util.ArrayList; public class potalos { private ArrayList<String> name = new ArrayList<String>(); private ArrayList<String> lat = new ArrayList<String>(); private ArrayList<String> lng = new ArrayList<String>(); private ArrayList<String> heure = new ArrayList<String>(); private ArrayList<String> litrage = new ArrayList<String>(); private ArrayList<String> voile = new ArrayList<String>(); public ArrayList<String> getName() { return name; } public void setName(String name) { this.name.add(name); } public ArrayList<String> getlat() { return lat; } public void setlat(String lat) { this.lat.add(lat); } public ArrayList<String> getlng() { return lng; } public void setlng(String lng) { this.lng.add(lng); } public ArrayList<String> getheure() { return heure; } public void setheure(String heure) { this.heure.add(heure); } public ArrayList<String> getlitrage() { return litrage; } public void setlitrage(String litrage) { this.litrage.add(litrage); } public ArrayList<String> getvoile() { return voile; } public void setvoile(String voile) { this.voile.add(voile); } }
monxmlhandler.java
bien sur mon MainCopainsActivity.class
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70 package com.lpc; import org.xml.sax.Attributes; import org.xml.sax.SAXException; import org.xml.sax.helpers.DefaultHandler; public class Monxmlhandler extends DefaultHandler { Boolean currentElement = false; String currentValue = null; public static potalos potalos = null; public static potalos getpotalos() { return potalos; } public static void setpotalos(potalos potalos) { Monxmlhandler.potalos = potalos; } @Override public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { currentElement = true; if (localName.equals("maintag")) { potalos = new potalos(); } else if (localName.equals("lat")) { String attr = attributes.getValue("lng"); potalos.setlng(attr); } } @Override public void endElement(String uri, String localName, String qName) throws SAXException { currentElement = false; /** set value */ if (localName.equalsIgnoreCase("name")) potalos.setName(currentValue); else if (localName.equalsIgnoreCase("lat")) potalos.setlat(currentValue); else if (localName.equalsIgnoreCase("lng")) potalos.setlng(currentValue); else if (localName.equalsIgnoreCase("heure")) potalos.setheure(currentValue); else if (localName.equalsIgnoreCase("litrage")) potalos.setlitrage(currentValue); else if (localName.equalsIgnoreCase("voile")) potalos.setvoile(currentValue); } @Override public void characters(char[] ch, int start, int length) throws SAXException { if (currentElement) { currentValue = new String(ch, start, length); currentElement = false; } } }
est bien déclaré dans le manifest et le fichier xml accessible durant mes tests
Partager