2010-11-16 230 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