0
votes

I am trying to create a simple source code reader that reads and displays the source-code of a web page using a URL entered in an EditText view, but can't initialise the InputSteramReader and the BufferedReader correctly. Testing this following code on Android 4.4.2, LogCat shows this error :

-->> SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length

URL url = null;

url = new URL(et.getText().toString());

URLConnection conn = url.openConnection();

InputStreamReader isr = new InputStreamReader(conn.getInputStream());

BufferedReader br = new BufferedReader(isr);


The connection is created successfully, but the last two lines cause error.I have set the permission to access internet in manifest file, used different input types for the edit-text view and tried defining buffer size, but that doesn't work either. Please help in identifying any mistakes in this code.

1

1 Answers

0
votes

Try transferring data to ByteArrayInputStream. I have this code working like a charm. Perhaps there is an encoding error also.

InputStream is = responce.getEntity().getContent();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    do {
        int b = is.read();
        if (b == -1)
            break;

        baos.write(b);
    } while (true);

    byte[] data = baos.toByteArray();

    ByteArrayInputStream bais = new ByteArrayInputStream(data);
    InputStreamReader isr = new InputStreamReader(bais, "UTF-8");
    BufferedReader br = new BufferedReader(isr);