Bonsoir,

J'ai essayé de stocker les URL dans une classe URLS, ou j'ai défini mes URL et les stocker dans un retour string grâce à la methode toString :


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
package com.toi;
import java.net.MalformedURLException;
import java.net.URL;
 
public class URLS  {
 
	public String s;
 
	   URL u1;
	   URL u2;
 
		public   String toString() 
		{
 
			   try 
			   {
				   u1 = new URL("http://www.ballouchi.com/xml/cat1/data.xml.php");
				   u2 = new URL("http://www.ballouchi.com/xml/cat/data.xml.php");
 
			   s= u1.toString();
		} 
			   catch (MalformedURLException e1) {
					e1.printStackTrace();
				}
 
 
			return s;
	}
	}
et je fait l'appelle de ses résultats dans une 2eme classe pour préparer le parse XML, ou je dois ajouter mon URL

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
package com.toi;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

import android.content.Context;

public class ContainerData {	
	
	static public Context context;
	
	public ContainerData() {

	}

	
	public static ArrayList<Entry> getEntries(){
		
		SAXParserFactory fabrique = SAXParserFactory.newInstance();
		SAXParser parseur = null;
		ArrayList<Entry> entries = null;
		
		try {
			
			parseur = fabrique.newSAXParser();
		} catch (ParserConfigurationException e) {
			e.printStackTrace();
		} catch (SAXException e) {
			e.printStackTrace();
		}
		
		
		
		URL url = null;
		try {
			
			url = new URL(URLS.toString()); **ERRONE**
			
		} catch (MalformedURLException e1) {
			e1.printStackTrace();
		}
		
		
		DefaultHandler handler = new ParserXMLHandler();
		try {
			
			parseur.parse(url.openConnection().getInputStream(), handler);
			
			entries = ((ParserXMLHandler) handler).getData();
		} catch (SAXException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		// On la retourne l'array list
		return entries;
	}

}
mais j'arrive pas a lire l'URL ==> une erreur qui s'affiche
Cannot make a static reference to the non-static method toString() from the type URLS test_forms/src/com/toi ContainerData.java line 46

pouvez vous m'aider afin d'adapter mon code?
merci