Я пытаюсь получить текст из .txt, расположенный на сервере в строку (feed_str) Мой код:AsyncTask возвращает нуль в OnPostExecute
public class getFeedData extends AsyncTask<String, Integer, String>
{
@Override
protected String doInBackground(String... params)
{
String feed_str = null;
try
{
// Create a URL for the desired page
URL url = new URL("http://www.this.is/a/server/file.txt");
// Read all the text returned by the server
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
while ((feed_str = in.readLine()) != null)
{
// str is one line of text; readLine() strips the newline character(s)
}
in.close();
}
catch (MalformedURLException e)
{
System.out.println("AsyncError: " + e);
}
catch (IOException e)
{
System.out.println("AsyncError: " + e);
}
catch (NullPointerException e)
{
System.out.println("AsyncError: " + e);
}
return feed_str;
}
@Override
protected void onPostExecute(String feed_str)
{
super.onPostExecute(feed_str);
System.out.println("onPostExecute " + feed_str);
}
С этим кодом LogCat должны вывести что-то вроде: "onPostExecute text from server"
, но вместо этого он выдает "onPostExecute null"
Любые идеи, как исправить?
Btw: URL-адрес был проверен браузером, и текст был отображен, чтобы URL-адреса не были проблемой.
Просьба заполнить полный логарифм. – thegrinner
опубликуйте полный код doInBackground, потому что, возможно, u не присваивает значение в 'feed_str' после строки чтения –