JavaME HttpConnection - ConnectionNotFoundException

时间:2012-12-20 14:44:11

标签: http java-me connection midlet

尝试使用任何网址建立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

0 个答案:

没有答案