Trying to push html code for the page in a variable and display it, but the performance of this code:
private class SearchTask extends AsyncTask<String, Void, String> {
String http = "";
@Override
protected String doInBackground(String... params) {
StringBuilder builder = new StringBuilder(16384);
DefaultHttpClient client = new DefaultHttpClient();
HttpGet get = new HttpGet("https://www.google.com.ua/");
try {
HttpResponse responce = client.execute(get);
InputStream content = responce.getEntity().getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(content));
while ((http = reader.readLine()) != null) {
builder.append(http);
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return builder.toString();
}
@Override
protected void onPostExecute(String s) {
editTxt.setText(s);
}
} flies error and application crash.
I can not understand what the problem is. Authorization for access to the Internet is given in the manifesto. Tell me what's wrong? Maybe there is a way easier to do this?
logcat:
08-08 16:54:25.030 23105-23236/com.example.ron.myapplication E/AndroidRuntime﹕ FATAL EXCEPTION: AsyncTask #3
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:299)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
at java.util.concurrent.FutureTask.run(FutureTask.java:239)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
at java.lang.Thread.run(Thread.java:838)
Caused by: java.lang.SecurityException: Permission denied (missing INTERNET permission?)
at java.net.InetAddress.lookupHostByName(InetAddress.java:430)
at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
at java.net.InetAddress.getAllByName(InetAddress.java:214)
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137)
at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:365)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
at com.example.ron.myapplication.MainActivity$SearchTask.doInBackground(MainActivity.java:93)
at com.example.ron.myapplication.MainActivity$SearchTask.doInBackground(MainActivity.java:80)
at android.os.AsyncTask$2.call(AsyncTask.java:287)
Caused by: libcore.io.GaiException: getaddrinfo failed: EAI_NODATA (No address associated with hostname)
at libcore.io.Posix.getaddrinfo(Native Method)
at libcore.io.ForwardingOs.getaddrinfo(ForwardingOs.java:59)
at java.net.InetAddress.lookupHostByName(InetAddress.java:405)
Caused by: libcore.io.ErrnoException: getaddrinfo failed: EACCES (Permission denied)