开发者

JavaME Midlet cannot establish HTTP Connection

开发者 https://www.devze.com 2023-01-25 16:25 出处:网络
I just downloaded the Java ME Platform SDK 3.0 and created my frist Midlet (from some Oracle Tutorial). Which works fine on the Emulator. When I deploy it on my Nokia N97 I can run it but as soon that

I just downloaded the Java ME Platform SDK 3.0 and created my frist Midlet (from some Oracle Tutorial). Which works fine on the Emulator. When I deploy it on my Nokia N97 I can run it but as soon that I press "Connect" and allow to proceed I get a IOException: -1

Here is the code:

package hello;
import java.io.*;
import javax.microedition.io.*;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class HelloMIDlet extends MIDlet implements CommandListener {

...

private void connect() {

HttpConnection hc = null;
InputStream in = null;
String url = getAppProperty("HitMIDlet.URL");

try {
  hc = (HttpConnection)Connector.open("http://www.google.ch"); 
  in = hc.openInputStream();
  by开发者_Go百科te[] raw = new byte[10];
  int length = in.read(raw);
  in.close();
  hc.close();

  // Show the response to the user.
  String s = new String(raw, 0, length);
  mMessageItem.setText(s);

}
catch (IOException ioe) {
  mMessageItem.setText( ioe.toString());
}
mDisplay.setCurrent(mMainForm);
}
}


You have working GPRS or internet connectivity in your phone + for your application ?

In many phone we have to set access point for app differently double check it

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号