BackgroundTask返回null为什么?它应该返回try块中指定的字符串

时间:2016-06-01 09:36:33

标签: android android-studio

BackgroundTask返回null。为什么?它应该返回try块中指定的字符串。

    @Override
    protected String doInBackground(Void...Voids)
    {


            try {

                URL url = new URL(json_url);
                HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
                InputStream ip = httpURLConnection.getInputStream();
                BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(ip));

                StringBuilder sb = new StringBuilder();
                while ((json_string = bufferedreader.readLine())!= null)
                {
                    sb.append(json_string + "\n");
                }
                bufferedreader.close();
                ip.close();
                httpURLConnection.disconnect();
                return sb.toString().trim();

            }
            catch (MalformedURLException e)
            {
                e.printStackTrace();
            }
            catch (IOException e)
            {
                e.printStackTrace();

            }



                        return null;
    }

1 个答案:

答案 0 :(得分:0)

您的return try区域内的logcat尚未到达,可能发生任何异常并且已被捕获。检查您的<ul class="mylist"> <li><a href="">link 1</a></li> <li><a href="">link 2</a></li> </ul> 并找到问题所在。