connecte à une page internet J2ME
salut
pour connecter à un page internet; j ai utilsé cett fonction:
void getViaStreamConnection(String url) throws IOException {
HttpConnection c = null;
InputStream is = null;
int rc;
try {
c = (HttpConnection)Connector.open(url);
// Getting the response code will open the connection,
// send the request, and read the HTTP response headers.
// The headers are stored until requested.
rc = c.getResponseCode();
if (rc != HttpConnection.HTTP_OK) {
throw new IOException("HTTP response code: " + rc);
}
is = c.openInputStream();
// Get the ContentType
String type = c.getType();
// Get the length and process the data
int len = (int)c.getLength();
if (len > 0) {
int actual = 0;
int bytesread = 0 ;
byte[] data = new byte[len];
while ((bytesread != len) && (actual != -1)) {
actual = is.read(data, bytesread, len - bytesread);
bytesread += actual;
}
} else {
int ch;
while ((ch = is.read()) != -1) {
}
}
} catch (ClassCastException e) {
throw new IllegalArgumentException("Not an HTTP URL");
} finally {
if (is != null)
is.close();
if (c != null)
c.close();
}
}
et lorsque je click sur OK je connecte à site google par exemple :
if (command == okCommand) {
// write pre-action user code here
switchDisplayable(null, getForm1());
// write post-action user code here
try {
getViaStreamConnection("www.google.com");
} catch (IOException ex) {
ex.printStackTrace();
}
mais à l'excution : je ne comprend rien où le probléme stp aide moi:
java.lang.IllegalArgumentException: no ':' in URL
at javax.microedition.io.Connector.openPrim(Connector.java:270)
at javax.microedition.io.Connector.open(Connector.java:222)
at javax.microedition.io.Connector.open(Connector.java:198)
at javax.microedition.io.Connector.open(Connector.java:180)
at hello.HelloMIDlet.getViaStreamConnection(HelloMIDlet.java:274)
at hello.HelloMIDlet.commandAction(HelloMIDlet.java:120)
at javax.microedition.lcdui.Display$DisplayAccessor.commandAction(Display.java:2093)
at javax.microedition.lcdui.Display$DisplayManagerImpl.commandAction(Display.java:2929)
at com.sun.midp.lcdui.DefaultEventHandler.commandEvent(DefaultEventHandler.java:297)
at com.sun.midp.lcdui.AutomatedEventHandler.commandEvent(AutomatedEventHandler.java:667)
at com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.handleVmEvent(DefaultEventHandler.java:711)
at com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.run(DefaultEventHandler.java:608)