开发者

Unable to retrieve the webpage programatically

开发者 https://www.devze.com 2023-04-12 20:09 出处:网络
I wrote a simple program in that retrieves google home page. the code is below: HttpConnection conn = (HttpConnection) Connector.open(url, Connector.READ_WRITE);

I wrote a simple program in that retrieves google home page. the code is below:

HttpConnection conn = (HttpConnection) Connector.open(url, Connector.READ_WRITE);
conn.setRequestMethod(HttpConnection.GET);
int responseCode = conn.getResponseCode();
if(responseCode == HttpConnection.HTTP_OK){
    InputStream data = conn.openInputStream();
    StringBuffer raw = new StringBuffer();
    byte[] buf = new byte[4096];
    int nRead = data.read(buf);
    while(nRead > 0){
        raw.append(new String(buf, 0, nRead));
        nRead = data.read(buf);
    }
    dest.updateDestination(raw.toString());

}
else
    dest.updateDestination("responseCode="+ Integer.toString(responseCode));            
    }
    catch(IOException e){
        e.printStackTrace();
        dest.updateDestination("Exception:"+e.toString());
    }

This is my main screen:

MenuItem getDataAction = new MenuItem("GetData", 100, 10){
        public void run(){
            String URL = "http://www.google.com";
            ServiceRequestThread svc = new ServiceRequestThread(URL, (MyScreen)
                    UiApplication.getUiApplication().getActiveScreen());
            svc.start();
     开发者_如何学编程   }
    };
    addMenuItem(getDataAction);
}

public void updateDestination(final String text){
    UiApplication.getUiApplication().invokeLater(new Runnable(){
        public void run(){
            output.setText(text);
        }
    });
}

When i am running my application on the simulator, i am getting the exception that is caught as Exception:java.io.IOException:Radio is Off I am using eclipse IDE. Should i change any properties in the eclipse or simulator. why am i getting this exception. What is the solution. Thank you


In the simulator menu, go to Simulate -> Network Properties and look at the available networks to make sure "In Coverage" is ticked. Also in on the simulated device, go to the Manage Connections menu and make sure you have the Mobile Network enabled.

0

精彩评论

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

关注公众号