AsyncTask failed to download web content

298 views Asked by At

i would really appreciate if someone could tell me what's wrong with my code that i'm not be able to complete the download of the web page using AsyncTask Class and doinbackground method : it'll give me only a few lines of html code and then i get an error :

 public class ApiWeather extends AsyncTask<String,Void,String>{

  @Override
  protected String doInBackground(String... urls) {
      String res="";
      URL url;
      HttpURLConnection httpURLConnection=null;
      try {
          url=new URL(urls[0]);
          httpURLConnection=(HttpURLConnection)url.openConnection();
          InputStream inputStream=httpURLConnection.getInputStream();
          InputStreamReader inputStreamReader=new 
InputStreamReader(inputStream);
          int Data=inputStreamReader.read();
          while (Data!= -1){
              char  characters=(char)Data;
              res+=characters;
                Data=inputStreamReader.read();
          }
            return res;



      } catch (Exception e) {
          e.printStackTrace();
      }

      return null;
  }


}
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    ApiWeather Task=new ApiWeather();
    String myres="";
    try {
        myres=Task.execute("http://www.posh24.se/kandisar").get();
    } catch (InterruptedException e) {
        e.printStackTrace();
    } catch (ExecutionException e) {
        e.printStackTrace();
    }

    Log.i("web content : ", myres);

}



}

and here's the error that i get after downloading bunch of lines :

06/26 19:19:50: Launching app
$ adb install-multiple -r -t -p com.example.luck.practiceproj E:\androidapps\practiceproj\app\build\intermediates\split-apk\debug\slices\slice_8.apk 
Split APKs installed
$ adb shell am start -n "com.example.luck.practiceproj/com.example.luck.practiceproj.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Client not ready yet..Waiting for process to come online
Connected to process 6563 on device emulator-5554
Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page.
I/ck.practicepro: The ClassLoaderContext is a special shared library.
W/ck.practicepro: JIT profile information will not be recorded: profile file does not exits.
I/chatty: uid=10084(com.example.luck.practiceproj) identical 10 lines
W/ck.practicepro: JIT profile information will not be recorded: profile file does not exits.
I/InstantRun: starting instant run server: is main process
W/ck.practicepro: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (light greylist, reflection)
W/ck.practicepro: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (light greylist, reflection)
D/NetworkSecurityConfig: No Network Security Config specified, using platform default
I/ck.practicepro: Waiting for a blocking GC ProfileSaver
I/ck.practicepro: WaitForGcToComplete blocked ProfileSaver on AddRemoveAppImageSpace for 20.162ms
I/web content :: <!DOCTYPE html>
                 <html>
                 <head>











                 <title>Topp 100 Kändisar - Posh24</title>
                 <base href="/"/>
                    <meta charset="ut-8"></meta>
                    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"></meta>
                    <meta name="robots" content="index,follow"></meta>
                    <meta name="viewport" content="width=device-width, initial-scale=1.0"></meta>
                    <meta name="apple-mobile-web-app-title" content="Posh24"></meta>
                    <meta name="google-site-verification" content="5cYwmuFA8gRoL9MJB9nmvs0F8XT0pSFj6ZhYy8RWkF4"></meta>
                    <meta name="description" content="Lista över topp 100 kändisar just nu! Vi listar de hetaste och mest omskrivna kändisar just nu med nyheter, bilder och videos."></meta>
                    <link rel="apple-touch-icon" href="/apple-touch-icon.png"></link>
                    <link rel="shortcut icon" href="/favicon.ico"></link>
                    <link rel="canonical" href="http://www.posh24.se/kandisar"></link>
                    <link rel="alternate" type="application/rss+xml" href="/feed" title="Kändis och nöjesnyheter från Posh24"></link>
                 <link href="//fonts.googleapis.com/css?family=Open+Sans:400,400italic,700,700italic" rel="stylesheet" type="text/css"/>
                            <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
                                <link href="css/news.css?p24v=54" rel="stylesheet" type="text/css" />


                            <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>

                            <script type="text/javascript" src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>

                            <script type="text/javascript" src="scripts/news-min.js?p24v=54"></script>

                            <script type="text/javascript" src="//posh24se.disqus.com/embed.js"></script>

                 <script type="text/javascript">
                 $(document).ready(function(){
                    if(typeof(framework)!=='undefined') {
                        framework.onPageLoad({"layout":"viewsite","unique":"54","uniquePrefix":"p24v="});
                    }
                 });
                 </script>
                 </head>
                 <body>









                 <div class="container">
                    <div class="row">
                        <div class="col-xs-12">
                            <div id="webx_header_1"><nav class="navbar navbar-inverse menu" data-x-onload="menuCtrl.init">
                   <div class="container-fluid">
                     <div class="navbar-header">
                       <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
                         <span class="icon-bar"></span>
                         <span class="icon-bar"></span>
                         <span class="icon-bar"></span> 
                       </button>
                       <a class="headerCenter" href="/">
                            <div class="logo"></div>
                      </a>
                     </div>
                     <div class="collapse navbar-collapse" id="myNavbar">
                       <ul class="nav navbar-nav">
                                    <li><a class="menuItem" href="/kandisar">Kändisar</a></li>
                                            <li><a class="menuItem" href="/nyheter">Senaste nytt</a></li>
                                    <li><a class="menuItem" href="/hant_i_sverige">Hänt i Sverige</a></li>
                                    <li><a class="menuItem" href="/svenska_kandisar">Svenska kändisar</a></li>
                                            <li class="visible-xs hidden-sm hidden-md hidden-lg"><a class="menuItem" href="/video">Video</a></li>
                                    <li class="visible-xs hidden-sm hidden-md hidden-lg"><a class="menuItem" href="/street_style">Street Style</a></li>
                              </ul>
                             <ul class="nav navbar-nav pull-right hidden-xs visible-sm visible-md visible-lg">
                        <li class="dropdown">
                            <a href="#" dropdown-toggle class="x-skip dropdown-toggle" data-toggle="dropdown">
                                <div class="toggle-icon"></div>
                            </a>
                            <ul class="dropdown-menu">
                                                    <li><a class="menuItem" href="/video">Video</a></li>
                                                    <li><a class="menuItem" href="/street_style">Street Style</a></li>
                                            </ul>
                        </li>
                      </ul>
                        </div>
                   </div>
                 </nav>
                 </div>
                        </div>  
                    </div>
                    <div class="row">
                        <div class="col-xs-12" id="banner_top">
                        </div>  
                    </div>
                    <div class="row">
                        <div class="col-xs-12 col-sm-6 col-md-8">
                            <div id="webx_center">


                 <div class="articleContainer contentBlock ">
                    <h1 class="header">Topp 100 kändisar</h1>   
                    <div class="channelList">
                        <div class="channels_nav">
                    <div class="title">Lista:</div>
                    <d
D/OpenGLRenderer: Skia GL Pipeline
D/: HostConnection::get() New Host Connection established 0xe50ffb00, tid 6589
I/ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0
               android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasHDRDisplay 
     retrieved: 0
     I/OpenGLRenderer: Initialized EGL, version 1.4
     D/OpenGLRenderer: Swap behavior 1
     W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED,         
     retrying without...
    D/OpenGLRenderer: Swap behavior 0
    D/EGL_emulation: eglCreateContext: 0xe8d83000: maj 3 min 1 rcv 4
    D/EGL_emulation: eglMakeCurrent: 0xe8d83000: ver 3 1 (tinfo 0xece31c00)
    E/eglCodecCommon: glUtilsParamSize: unknow param 0x000082da
                  glUtilsParamSize: unknow param 0x000082da
     D/EGL_emulation: eglMakeCurrent: 0xe8d83000: ver 3 1 (tinfo 0xece31c00)

i tried both Hardware and software Graphics

1

There are 1 answers

4
mtrewartha On BEST ANSWER

It looks to me as if LogCat is truncating the output of your log message because there's so much HTML crammed into it. The error logs after your logs look unrelated to your issue to me, so I'd guess your download is actually successful.