Not Reading text from server

前端 未结 2 1771
余生分开走
余生分开走 2021-01-28 02:08

I am trying to read all the text from server, I think that my code is not retrieving text from server will you please help me how can I fix this problem, I am new to android dev

相关标签:
2条回答
  • 2021-01-28 02:37

    May be you can try like this, just a thought only :

    StringBuilder content = new StringBuilder();
                    // read text returned by server
                    BufferedReader in = new BufferedReader(new InputStreamReader(new URL("http://www.google.com:80/").openConnection().getInputStream()));
                    String line;
                    while ((line = in.readLine()) != null) {
                        content.append(line +"\n");
                    }
    
    tv.setText(content.toString());
    setContentView(tv);
    
    0 讨论(0)
  • 2021-01-28 02:44

    Take these lines

    tv.setText(line);
    setContentView(tv);
    

    out of while loop

    Use StringBuilder object (declared before loop) in while loop and append the strings in that. After while loop take string from StringBuilder and do tv.setText(string)

    0 讨论(0)
提交回复
热议问题