开发者

Problem with getting source code of page

I'm new in Java and in programming on android. Have a look at this code:

TextView tv = new TextView(this);
URI uri;
HttpResponse response = null;
String str = "dupa2";
try {
    uri = new URI("http://google.com");
    HttpGet get = new HttpGet(uri);
    HttpClient client = new DefaultHttpClient();
    try {
        response = client.execute(get);
        HttpEntity enity = response.getEntity();
        str = enity.toString();
        str = "2";
    } catch (IOException ex) {
        tv.setText("blad");
        Logger.getLogger(MainActivity.class.getName()).log(Level.SEVERE, null, ex);
    }
} catch (URISyntaxException ex) {
    tv.setText("blad");
    Logger.getLogger(MainActivity.class.getName()).log(Level.SE开发者_如何转开发VERE, null, ex);
}
tv.setText(str);
setContentView(tv);

It doesn't work and i dont have idea why :/ str value is "dupa2" when it should be "2" (i added it because i didnt know whats going on) or "blad") WTF?

Must I add that try...catch statements? Thanks in advance, Chris


It seems that you've an exception thrown, so the tv text is set to "blad" and then again to "dupa2" (the 2nd line from the end).


Definitely you are getting an exception, add into your AndroidManifest.xml internet permission

<uses-permission android:name="android.permission.INTERNET"></uses-permission>

post your stacktrace if this not solve your problem

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜