1

I am totally new to android and trying to download a web content.Even though my code is throwing an error which I could not find where the Error happens and how to fix it.

public class MainActivity extends AppCompatActivity {

    public class DataDownload extends AsyncTask<String,Void,String>{
        @Override
        protected String doInBackground(String... urls) {
            String result= "";
            URL url;
            HttpURLConnection urlConnection = null;

            try {
                url =  new URL(urls[0]);
                urlConnection = (HttpURLConnection)url.openConnection();
                InputStream in = urlConnection.getInputStream();
                InputStreamReader reader = new InputStreamReader(in);
                int data = reader.read();
                while(data != -1){
                    char current = (char) data;
                    result += current;
                    data =  reader.read();

                }
                return result;
            } catch (IOException e) {
                e.printStackTrace();
                return "Failed";

            }
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        DataDownload task = new DataDownload();

        String result = null;

        try {

            result = task.execute("https://www.ecowebhosting.co.uk/").get();

        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        Log.i("content",result); }

I am getting this log

 10-25 22:04:39.766: E/ActivityThread(2617): Failed to find provider info for com.google.android.apps.gsa.testing.ui.audio.recorded
 10-25 22:04:39.813: E/cutils-trace(8731): Error opening trace file: Permission denied (13)
 10-25 22:04:40.293: E/memtrack(8731): Couldn't  load memtrack module (No such file or directory)
 10-25 22:04:40.298: E/android.os.Debug(8731): failed to load memtrack module: -2
 10-25 22:04:40.385: E/NetworkScheduler.SR(2599): Invalid parameter app
 10-25 22:04:40.385: E/NetworkScheduler.SR(2599): Invalid package name :      Perhaps you didn't include a PendingIntent in the extras?
 10-25 22:04:40.500: E/Drive.UninstallOperation(2784): Package still      installed com.nejat.listviewdemo
 10-25 22:04:40.922: E/NetworkScheduler.SR(2599): Invalid parameter app
 10-25 22:04:40.922: E/NetworkScheduler.SR(2599): Invalid package name : Perhaps you didn't include a PendingIntent in the extras?
 10-25 22:04:43.103: E/cutils-trace(8780): Error opening trace file: Permission denied (13)
 10-25 22:04:43.389: E/memtrack(8780): Couldn't load memtrack module (No such file or directory)
 10-25 22:04:43.389: E/android.os.Debug(8780): failed to load memtrack module: -2
 10-25 22:05:33.724: E/SurfaceFlinger(1294): ro.sf.lcd_density must be defined as a build property
 10-25 22:05:33.724: E/SurfaceFlinger(1294): [ 10-25 22:05:33.730  8793: 8793 D/         ]
 10-25 22:05:33.724: E/SurfaceFlinger(1294): HostConnection::get() New Host Connection established 0x9ae3a4c0, tid 8793 

Thank you in advance.

deathangel908
  • 8,601
  • 8
  • 47
  • 81
Nejweti
  • 113
  • 2
  • 11
  • Please provide the logcat from your app including debug level. I asume you pasted the system. https://stackoverflow.com/questions/6854127/filter-logcat-to-get-only-the-messages-from-my-application-in-android – deathangel908 Oct 25 '17 at 22:30
  • `execute().get()` defeats the purpose of an asynctask. You have made it synced. – OneCricketeer Oct 25 '17 at 22:56
  • Also, `SurfaceFlinger(1294): HostConnection::get()`... SurfaceFlinger is not your package name, therefore, that is not an error you should worry about – OneCricketeer Oct 25 '17 at 22:58
  • Thank you, I didnt know how to check the logcat from the app and It is working there. – Nejweti Oct 26 '17 at 10:03

0 Answers0