「 http://www.posh24.se/kandisar 」というウェブサイトのコンテンツをダウンロードしようとしています。何百回もプログラムをチェックしましたが、解決策が見つかりませんでした。調べてください。Web サイトのすべてのコンテンツをログに記録しようとしていますが、「失敗」メッセージしか表示されません。
MainActivity.java
package com.example.kiran.guessthecelebritygame;
import android.graphics.Bitmap;
import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.concurrent.ExecutionException;
public class MainActivity extends AppCompatActivity {
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]);
Log.i("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!";
}
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
DownloadTask task=new DownloadTask();
String result="";
try {
result=task.execute("http://www.posh24.se/kandisar").get();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
Log.i("Content of Url: ", result);
}
}
そしてLogcatは
06-30 07:40:02.582 23015-23015/? I/hecelebritygam: Not late-enabling -Xcheck:jni (already on)
06-30 07:40:02.611 23015-23015/? W/hecelebritygam: Unexpected CPU variant for X86 using defaults: x86
06-30 07:40:02.884 23015-23015/com.example.kiran.guessthecelebritygame W/hecelebritygam: JIT profile information will not be recorded: profile file does not exits.
06-30 07:40:02.889 23015-23015/com.example.kiran.guessthecelebritygame I/chatty: uid=10101(com.example.kiran.guessthecelebritygame) identical 10 lines
06-30 07:40:02.890 23015-23015/com.example.kiran.guessthecelebritygame W/hecelebritygam: JIT profile information will not be recorded: profile file does not exits.
06-30 07:40:02.933 23015-23015/com.example.kiran.guessthecelebritygame I/InstantRun: starting instant run server: is main process
06-30 07:40:03.688 23015-23026/com.example.kiran.guessthecelebritygame I/hecelebritygam: Background concurrent copying GC freed 6131(2MB) AllocSpace objects, 0(0B) LOS objects, 54% free, 1305KB/2MB, paused 8.282ms total 280.862ms
06-30 07:40:03.753 23015-23015/com.example.kiran.guessthecelebritygame W/hecelebritygam: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (light greylist, reflection)
06-30 07:40:03.754 23015-23015/com.example.kiran.guessthecelebritygame W/hecelebritygam: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (light greylist, reflection)
06-30 07:40:04.002 23015-23041/com.example.kiran.guessthecelebritygame I/URL:: http://gogarbhaipa.com/
06-30 07:40:04.054 23015-23041/com.example.kiran.guessthecelebritygame D/NetworkSecurityConfig: No Network Security Config specified, using platform default
06-30 07:40:04.073 23015-23041/com.example.kiran.guessthecelebritygame W/System.err: java.io.IOException: Cleartext HTTP traffic to gogarbhaipa.com not permitted
06-30 07:40:04.075 23015-23041/com.example.kiran.guessthecelebritygame W/System.err: at com.android.okhttp.HttpHandler$CleartextURLFilter.checkURLPermitted(HttpHandler.java:115)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:458)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:407)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:244)
at com.example.kiran.guessthecelebritygame.MainActivity$DownloadTask.doInBackground(MainActivity.java:36)
06-30 07:40:04.077 23015-23041/com.example.kiran.guessthecelebritygame W/System.err: at com.example.kiran.guessthecelebritygame.MainActivity$DownloadTask.doInBackground(MainActivity.java:18)
at android.os.AsyncTask$2.call(AsyncTask.java:333)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
06-30 07:40:04.078 23015-23041/com.example.kiran.guessthecelebritygame W/System.err: at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
06-30 07:40:04.097 23015-23041/com.example.kiran.guessthecelebritygame W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764)
06-30 07:40:04.098 23015-23015/com.example.kiran.guessthecelebritygame I/Content of Url:: Failed!
06-30 07:40:04.171 23015-23015/com.example.kiran.guessthecelebritygame D/OpenGLRenderer: HWUI GL Pipeline
06-30 07:40:04.382 23015-23043/com.example.kiran.guessthecelebritygame I/ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0
android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasHDRDisplay retrieved: 0
06-30 07:40:04.382 23015-23043/com.example.kiran.guessthecelebritygame I/OpenGLRenderer: Initialized EGL, version 1.4
06-30 07:40:04.382 23015-23043/com.example.kiran.guessthecelebritygame D/OpenGLRenderer: Swap behavior 1
06-30 07:40:04.383 23015-23043/com.example.kiran.guessthecelebritygame W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
06-30 07:40:04.383 23015-23043/com.example.kiran.guessthecelebritygame D/OpenGLRenderer: Swap behavior 0
06-30 07:40:04.402 23015-23043/com.example.kiran.guessthecelebritygame D/EGL_emulation: eglCreateContext: 0xe0205300: maj 2 min 0 rcv 2
06-30 07:40:04.417 23015-23043/com.example.kiran.guessthecelebritygame D/EGL_emulation: eglMakeCurrent: 0xe0205300: ver 2 0 (tinfo 0xe0203780)
06-30 07:40:04.509 23015-23043/com.example.kiran.guessthecelebritygame D/EGL_emulation: eglMakeCurrent: 0xe0205300: ver 2 0 (tinfo 0xe0203780)
実行すると、logcatの上に表示されます。何が悪いのかわかりません。なぜ失敗し続けるのか。簡単な答えが得られることを願っています。私はまだアンドロイドの学習者です。