2010-11-16 95 views
1

我刚刚下载了Java ME Platform SDK 3.0并创建了我的第一个Midlet(来自一些Oracle教程)。在模拟器上工作正常。当我在我的诺基亚N97部署它,我能够尽快,我按下“连接”,并允许继续我得到一个IOException异常运行它,但是:-1JavaME Midlet无法建立HTTP连接

下面是代码:

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(); 
    byte[] 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); 
} 
} 

回答

2

你有在您的手机中使用GPRS或互联网连接+为您的应用程序?

在许多手机中,我们必须设置不同的应用接入点,请仔细检查它

+0

非常感谢。就是这样。很简单。 – 2010-11-18 09:56:23

+0

@Marcel Menz欢迎您:) – 2010-11-18 10:06:19