尝试使用任何 url 建立 HttpConnection 时出现问题。
尝试查找它,但没有运气。我正在使用它附带的 NetBeans 7.2.1 和 JavaMe SDK 3.2;赢得 7 x64。任何帮助表示赞赏。
我的代码:
public void connect() {
HttpConnection c = null;
InputStream is = null;
StringBuffer sb = new StringBuffer();
try {
c = (HttpConnection) Connector.open("http://www.google.com");
is = c.openInputStream();
int ch = 0;
for (int ccnt = 0; ccnt < 150; ccnt++) {
ch = is.read();
if (ch == -1) {
break;
}
sb.append((char) ch);
}
} catch (IOException x) {
x.printStackTrace();
} finally {
try {
is.close();
c.close();
} catch (IOException x) {
x.printStackTrace();
}
}
}
运行后,我收到以下错误:
javax.microedition.io.ConnectionNotFoundException: error 10049 in socket::open
at com.sun.midp.io.j2me.socket.Protocol.open0(), bci=0
at com.sun.midp.io.j2me.socket.Protocol.connect(), bci=184
at com.sun.midp.io.j2me.socket.Protocol.open(), bci=216
at com.sun.midp.io.j2me.socket.Protocol.openPrim(), bci=4
at com.sun.midp.io.j2me.http.Protocol.createConnection(), bci=41
at com.sun.midp.io.j2me.http.Protocol.connect(), bci=41
at com.sun.midp.io.j2me.http.Protocol.streamConnect(), bci=164
at com.sun.midp.io.j2me.http.Protocol.startRequest(), bci=7
at com.sun.midp.io.j2me.http.Protocol.sendRequest(), bci=33
at com.sun.midp.io.j2me.http.Protocol.sendRequest(), bci=3
at com.sun.midp.io.j2me.http.Protocol.openInputStream(), bci=6
- hello.HelloMIDlet.connect(HelloMIDlet.java:308)
- hello.HelloMIDlet.startApp(HelloMIDlet.java:262)
at javax.microedition.midlet.MIDletTunnelImpl.callStartApp(), bci=1
at com.sun.midp.midlet.MIDletPeer.startApp(), bci=5
at com.sun.midp.midlet.MIDletStateHandler.startSuite(), bci=261
at com.sun.midp.main.AbstractMIDletSuiteLoader.startSuite(), bci=38
at com.sun.midp.main.CldcMIDletSuiteLoader.startSuite(), bci=5
at com.sun.midp.main.AbstractMIDletSuiteLoader.runMIDletSuite(), bci=144
at com.sun.midp.main.AppIsolateMIDletSuiteLoader.main(), bci=26
TRACE: <at java.lang.NullPointerException: 0>, startApp threw an Exception
java.lang.NullPointerException: 0
- hello.HelloMIDlet.connect(HelloMIDlet.java:321)
- hello.HelloMIDlet.startApp(HelloMIDlet.java:262)
at javax.microedition.midlet.MIDletTunnelImpl.callStartApp(), bci=1
at com.sun.midp.midlet.MIDletPeer.startApp(), bci=5
at com.sun.midp.midlet.MIDletStateHandler.startSuite(), bci=261
at com.sun.midp.main.AbstractMIDletSuiteLoader.startSuite(), bci=38
at com.sun.midp.main.CldcMIDletSuiteLoader.startSuite(), bci=5
at com.sun.midp.main.AbstractMIDletSuiteLoader.runMIDletSuite(), bci=144
at com.sun.midp.main.AppIsolateMIDletSuiteLoader.main(), bci=26
java.lang.NullPointerException: 0
- hello.HelloMIDlet.connect(HelloMIDlet.java:321)
- hello.HelloMIDlet.startApp(HelloMIDlet.java:262)
at javax.microedition.midlet.MIDletTunnelImpl.callStartApp(), bci=1
at com.sun.midp.midlet.MIDletPeer.startApp(), bci=5
at com.sun.midp.midlet.MIDletStateHandler.startSuite(), bci=261
at com.sun.midp.main.AbstractMIDletSuiteLoader.startSuite(), bci=38
at com.sun.midp.main.CldcMIDletSuiteLoader.startSuite(), bci=5
at com.sun.midp.main.AbstractMIDletSuiteLoader.runMIDletSuite(), bci=144
at com.sun.midp.main.AppIsolateMIDletSuiteLoader.main(), bci=26