[debug] erreur que je ne comprend pas
Bonjour bonjour,
j'essaie de faire une httpconnection en me basant un code source d'un tuto que j'ai trouvé sur internet, et je ne parviens pas à compiler le code j'ai toujours cette erreur :
Code:
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
|
C:\WTK25\apps\dips\src\dips.java:148: unreported exception java.io.IOException; must be caught or declared to be thrown
iStrm.close();
^
C:\WTK25\apps\dips\src\dips.java:152: unreported exception java.io.IOException; must be caught or declared to be thrown
http.close();
^
C:\WTK25\apps\dips\src\dips.java:127: unreported exception java.io.IOException; must be caught or declared to be thrown
http = (HttpConnection) Connector.open(url);
^
C:\WTK25\apps\dips\src\dips.java:129: unreported exception java.io.IOException; must be caught or declared to be thrown
http.setRequestMethod(HttpConnection.GET);
^
C:\WTK25\apps\dips\src\dips.java:130: unreported exception java.io.IOException; must be caught or declared to be thrown
http.setRequestProperty("User-Agent", "Profile/MIDP-1.0 Configuration/CLDC-1.0");
^
C:\WTK25\apps\dips\src\dips.java:132: unreported exception java.io.IOException; must be caught or declared to be thrown
if (http.getResponseCode() == HttpConnection.HTTP_OK)
^
C:\WTK25\apps\dips\src\dips.java:134: unreported exception java.io.IOException; must be caught or declared to be thrown
iStrm = http.openInputStream();
^
C:\WTK25\apps\dips\src\dips.java:139: unreported exception java.io.IOException; must be caught or declared to be thrown
iStrm.read(serverData);
^ |
Pourtant j'utilise la structure try {} poour faire ma connexion :
Code:
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
|
public void mise_a_jour_gprs()
{
String url = "http://www.google.ch";
HttpConnection http = null;
InputStream iStrm = null;
try
{
http = (HttpConnection) Connector.open(url);
http.setRequestMethod(HttpConnection.GET);
http.setRequestProperty("User-Agent", "Profile/MIDP-1.0 Configuration/CLDC-1.0");
if (http.getResponseCode() == HttpConnection.HTTP_OK)
{
iStrm = http.openInputStream();
int length = (int) http.getLength();
if (length > 0)
{
byte serverData[] = new byte[length];
iStrm.read(serverData);
System.err.println(serverData.toString());
}
}
}
finally
{
if (iStrm != null)
{
iStrm.close();
}
if (http != null)
{
http.close();
}
}
} |
J'ai essayé de mettre les close() dans un catch, ou meme à la suite dans le programme, mais rien y fait, j'ai toujours cette erreur.
Si quelqu'un pouvait m'aider ça serait sympa.
Merci d'avance.