0

I wanted to get the content(HTML) from website and while running the app i am getting this run time error, and i am not able to resolve this.

Main Activity This is my java code to read data from website and log the result in LOGCAT window,I have tried various solution for this even is re download my android studio.

package com.example.demo;

import **androidx.appcompat.app.AppCompatActivity**;


import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class MainActivity extends AppCompatActivity {


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

        DownloadTask task = new DownloadTask();
        String result = null;
        try {
            //sending utl to class method doInBackground()
            result = task.execute("http://www.ecowebhosting.co.uk").get();
        } catch (Exception e) {
            e.printStackTrace();
        }
        Log.i("Result", result);
    }

    public class DownloadTask 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 (Exception e) {
                e.printStackTrace();
                return "Failed";
            }

        }
    }
}

error This is the error popped up on my LOGCAT window and i don't know how to resolve this.

2021-04-28 23:23:35.339 8332-8332/? I/om.example.dem: Late-enabling -Xcheck:jni
2021-04-28 23:23:35.372 8332-8332/? E/om.example.dem: Unknown bits set in runtime_flags: 0x28000
2021-04-28 23:23:35.457 8332-8332/com.example.demo I/Perf: Connecting to perf service.
2021-04-28 23:23:35.473 8332-8359/com.example.demo E/Perf: Fail to get file list com.example.demo
2021-04-28 23:23:35.473 8332-8359/com.example.demo E/Perf: getFolderSize() : Exception_1 = java.lang.NullPointerException: Attempt to get length of null array
2021-04-28 23:23:35.474 8332-8359/com.example.demo E/Perf: Fail to get file list com.example.demo
2021-04-28 23:23:35.474 8332-8359/com.example.demo E/Perf: getFolderSize() : Exception_1 = java.lang.NullPointerException: Attempt to get length of null array
2021-04-28 23:23:35.474 8332-8359/com.example.demo E/Perf: Fail to get file list oat
2021-04-28 23:23:35.474 8332-8359/com.example.demo E/Perf: getFolderSize() : Exception_1 = java.lang.NullPointerException: Attempt to get length of null array

0 Answers0