Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 异步任务不是';获取网页的html内容并不完美_Java_Android_Android Asynctask - Fatal编程技术网

Java 异步任务不是';获取网页的html内容并不完美

Java 异步任务不是';获取网页的html内容并不完美,java,android,android-asynctask,Java,Android,Android Asynctask,我在这里是一个初学者,并遵循一个教程,该教程使用异步任务在我的Logcat中获取网页,但我的应用程序只能保护来自极少数站点的页面,在许多站点上,它返回空白或生成非常不可读的HTML格式。另外,由于AsyncTask越来越不受欢迎,请告诉我们如何高效地执行相同的功能。可能使用处理程序、截击、改装、服务或其他方式。任何帮助都将不胜感激 public class MainActivity extends AppCompatActivity { public class downloadPage ex

我在这里是一个初学者,并遵循一个教程,该教程使用异步任务在我的Logcat中获取网页,但我的应用程序只能保护来自极少数站点的页面,在许多站点上,它返回空白或生成非常不可读的HTML格式。另外,由于AsyncTask越来越不受欢迎,请告诉我们如何高效地执行相同的功能。可能使用处理程序、截击、改装、服务或其他方式。任何帮助都将不胜感激

public class MainActivity extends AppCompatActivity {

public class downloadPage 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 inside = urlConnection.getInputStream();
            InputStreamReader reader = new InputStreamReader(inside);
            int data = reader.read();

            while (data != -1){
                char current = (char) data;
                 result += current;

                 data = reader.read();
            }

            return result;

        } catch (Exception e) {
            Log.e("Here is","The error",e);
        }

        return "Task Done";
    }
}

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

    downloadPage page = new downloadPage();
    String result = null;
    try {
        result = page.execute("https://docs.python.org/3/").get();
    } catch (Exception e){
        Log.e("TAG","this is the error",e);
    }
    Log.i("Result is",result);
}}
public类MainActivity扩展了AppCompatActivity{
公共类下载页扩展异步任务{
@凌驾
受保护的字符串doInBackground(字符串…URL){
字符串结果=”;
网址;
HttpURLConnection-urlConnection=null;
试一试{
url=新url(url[0]);
urlConnection=(HttpURLConnection)url.openConnection();
InputStream inside=urlConnection.getInputStream();
InputStreamReader reader=新的InputStreamReader(内部);
int data=reader.read();
while(数据!=-1){
当前字符=(字符)数据;
结果+=电流;
data=reader.read();
}
返回结果;
}捕获(例外e){
Log.e(“这里是”,“错误”,e);
}
返回“任务完成”;
}
}
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
downloadPage=新建downloadPage();
字符串结果=null;
试一试{
结果=第页。执行(“https://docs.python.org/3/).get();
}捕获(例外e){
Log.e(“标记”,“这是错误”,e);
}
Log.i(“结果为”,结果);
}}
虽然我得到了HTML,但是我的logcat中仍然有一些错误。给你-

10-12 19:11:18.101 16464-16464/? I/webcontentintr: Not late-enabling -Xcheck:jni (already on)
10-12 19:11:18.173 16464-16464/? I/webcontentintr: Unquickening 12 vdex files!
10-12 19:11:18.176 16464-16464/? W/webcontentintr: Unexpected CPU variant for X86 using defaults: x86
10-12 19:11:18.605 16464-16464/com.example.vaibhav.webcontentintro D/ApplicationLoaders: Returning zygote-cached class loader: /system/framework/android.test.base.jar
10-12 19:11:18.607 16464-16464/com.example.vaibhav.webcontentintro I/webcontentintr: The ClassLoaderContext is a special shared library.
10-12 19:11:19.021 16464-16464/com.example.vaibhav.webcontentintro W/webcontentintr: JIT profile information will not be recorded: profile file does not exist.
10-12 19:11:19.035 16464-16464/com.example.vaibhav.webcontentintro I/chatty: uid=10169(com.example.vaibhav.webcontentintro) identical 9 lines
10-12 19:11:19.035 16464-16464/com.example.vaibhav.webcontentintro W/webcontentintr: JIT profile information will not be recorded: profile file does not exist.
10-12 19:11:19.304 16464-16464/com.example.vaibhav.webcontentintro D/NetworkSecurityConfig: No Network Security Config specified, using platform default
10-12 19:11:19.308 16464-16464/com.example.vaibhav.webcontentintro D/NetworkSecurityConfig: No Network Security Config specified, using platform default
10-12 19:11:19.326 16464-16464/com.example.vaibhav.webcontentintro I/InstantRun: starting instant run server: is main process
10-12 19:11:19.741 16464-16499/com.example.vaibhav.webcontentintro D/libEGL: loaded /vendor/lib/egl/libEGL_emulation.so
10-12 19:11:19.847 16464-16499/com.example.vaibhav.webcontentintro D/libEGL: loaded /vendor/lib/egl/libGLESv1_CM_emulation.so
10-12 19:11:19.879 16464-16499/com.example.vaibhav.webcontentintro D/libEGL: loaded /vendor/lib/egl/libGLESv2_emulation.so
10-12 19:11:20.407 16464-16464/com.example.vaibhav.webcontentintro I/webcontentintr: IncrementDisableThreadFlip blocked for 7.872ms
10-12 19:11:20.455 16464-16464/com.example.vaibhav.webcontentintro I/webcontentintr: Waiting for a blocking GC ClassLinker
10-12 19:11:20.573 16464-16464/com.example.vaibhav.webcontentintro I/webcontentintr: WaitForGcToComplete blocked ClassLinker on ClassLinker for 117.552ms
10-12 19:11:20.574 16464-16464/com.example.vaibhav.webcontentintro W/webcontentintr: Verification of void android.support.v4.view.ViewCompat.addOnUnhandledKeyEventListener(android.view.View, android.support.v4.view.ViewCompat$OnUnhandledKeyEventListenerCompat) took 119.090ms (604.58 bytecodes/s) (1784B approximate peak alloc)
10-12 19:11:20.745 16464-16464/com.example.vaibhav.webcontentintro W/webcontentintr: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed)
10-12 19:11:20.748 16464-16464/com.example.vaibhav.webcontentintro W/webcontentintr: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed)
10-12 19:11:22.545 16464-16464/com.example.vaibhav.webcontentintro I/Result is: <html>
                                                                                <head><title>301 Moved Permanently</title></head>
                                                                                <body bgcolor="white">
                                                                                <center><h1>301 Moved Permanently</h1></center>
                                                                                <hr><center>nginx/1.14.0 (Ubuntu)</center>
                                                                                </body>
                                                                                </html>
10-12 19:11:22.678 16464-16464/com.example.vaibhav.webcontentintro V/StudioProfiler: StudioProfilers agent attached.
10-12 19:11:22.828 16464-16464/com.example.vaibhav.webcontentintro W/webcontentintr: DexFile /data/user/0/com.example.vaibhav.webcontentintro/perfa.jar is in boot class path but is not in a known location
10-12 19:11:22.843 16464-16540/com.example.vaibhav.webcontentintro V/StudioProfiler: Acquiring Application for Events
10-12 19:11:22.663 16464-16464/com.example.vaibhav.webcontentintro W/webcontentintro: type=1400 audit(0.0:705): avc: granted { execute } for path="/data/user/0/com.example.vaibhav.webcontentintro/libperfa_x86.so" dev="vdc" ino=131501 scontext=u:r:untrusted_app_27:s0:c512,c768 tcontext=u:object_r:app_data_file:s0:c512,c768 tclass=file app=com.example.vaibhav.webcontentintro
10-12 19:11:22.880 16464-16541/com.example.vaibhav.webcontentintro W/InputMethodManager: InputMethodManager.getInstance() is deprecated because it cannot be compatible with multi-display. Use context.getSystemService(InputMethodManager.class) instead.
                                                                                         java.lang.Throwable
                                                                                             at android.view.inputmethod.InputMethodManager.getInstance(InputMethodManager.java:1234)
                                                                                             at java.lang.reflect.Method.invoke(Native Method)
                                                                                             at com.android.tools.profiler.support.profilers.EventProfiler$InputConnectionHandler.run(EventProfiler.java:287)
                                                                                             at java.lang.Thread.run(Thread.java:923)
10-12 19:11:22.902 16464-16541/com.example.vaibhav.webcontentintro W/InputMethodManager: InputMethodManager.peekInstance() is deprecated because it cannot be compatible with multi-display. Use context.getSystemService(InputMethodManager.class) instead.
                                                                                         java.lang.Throwable
                                                                                             at android.view.inputmethod.InputMethodManager.peekInstance(InputMethodManager.java:1253)
                                                                                             at android.view.inputmethod.InputMethodManager.getInstance(InputMethodManager.java:1239)
                                                                                             at java.lang.reflect.Method.invoke(Native Method)
                                                                                             at com.android.tools.profiler.support.profilers.EventProfiler$InputConnectionHandler.run(EventProfiler.java:287)
                                                                                             at java.lang.Thread.run(Thread.java:923)
10-12 19:11:23.215 16464-16464/com.example.vaibhav.webcontentintro A/libc: Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 16464 (webcontentintro), pid 16464 (webcontentintro)
10-12 19:11:18.101 16464-16464/?I/webcontentintr:未延迟启用-Xcheck:jni(已启用)
10-12 19:11:18.173 16464-16464/? I/webcontentintr:取消12个vdex文件!
10-12 19:11:18.176 16464-16464/? W/webcontentintr:使用默认值的X86的意外CPU变量:X86
10-12 19:11:18.605 16464-16464/com.example.vaibhav.webcontentintro D/ApplicationLoaders:返回zygote缓存类加载器:/system/framework/android.test.base.jar
10-12 19:11:18.607 16464-16464/com.example.vaibhav.webcontentintro I/webcontentintr:ClassLoaderContext是一个特殊的共享库。
10-12 19:11:19.021 16464-16464/com.example.vaibhav.webcontentintro W/webcontentintr:将不记录JIT配置文件信息:配置文件不存在。
10-12 19:11:19.035 16464-16464/com.example.vaibhav.webcontentintro I/chatty:uid=10169(com.example.vaibhav.webcontentintro)相同的9行
10-12 19:11:19.035 16464-16464/com.example.vaibhav.webcontentintro W/webcontentintr:将不记录JIT配置文件信息:配置文件不存在。
10-12 19:11:19.304 16464-16464/com.example.vaibhav.webcontentintro D/NetworkSecurityConfig:未指定网络安全配置,使用平台默认值
10-12 19:11:19.308 16464-16464/com.example.vaibhav.webcontentintro D/NetworkSecurityConfig:未指定网络安全配置,使用平台默认值
10-12 19:11:19.326 16464-16464/com.example.vaibhav.webcontentintro I/InstantRun:启动即时运行服务器:是主进程
10-12 19:11:19.741 16464-16499/com.example.vaibhav.webcontentintro D/libEGL:loaded/vendor/lib/egl/libEGL_.so
10-12 19:11:19.847 16464-16499/com.example.vaibhav.webcontentintro D/libEGL:loaded/vendor/lib/egl/libGLESv1_CM_emulation.so
10-12 19:11:19.879 16464-16499/com.example.vaibhav.webcontentintro D/libEGL:loaded/vendor/lib/egl/libGLESv2_emulation.so
10-12 19:11:20.407 16464-16464/com.example.vaibhav.webcontentintro I/webcontentintr:IncrementDisableThreadFlip被阻止7.872ms
10-12 19:11:20.455 16464-16464/com.example.vaibhav.webcontentintro I/webcontentintr:正在等待阻止的GC类链接器
10-12 19:11:20.573 16464-16464/com.example.vaibhav.webcontentintro I/webcontentintr:WaitForgCTO在类链接器上完成阻止的类链接器117.552ms
10-12 19:11:20.574 16464-16464/com.example.vaibhav.webcontentintro W/webcontentintr:void android.support.v4.view.ViewCompat.addOnUnhandledKeyEventListener(android.view.view,android.support.v4.view.ViewCompat$OnUnhandledKeyEventListenerCompat)的验证耗时119.090ms(604.58字节码/秒)(1784B近似峰值分配)
10-12 19:11:20.745 16464-16464/com.example.vaibhav.webcontentintro W/webcontentintr:访问隐藏方法Landroid/view/view;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z(灰色列表,允许反射)
10-12 19:11:20.748 16464-16464/com.example.vaibhav.webcontentintro W/webcontentintr:访问隐藏方法Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V(灰色列表,允许反射)
10-12 19:11:22.545 16464-16464/com.example.vaibhav.webcontentintro I/结果是:
301永久搬迁
301永久搬迁

nginx/1.14.0(Ubuntu) 10-12 19:11:22.678 16464-16464/com.example.vaibhav.webcontentintro V/StudioProfiler:StudioProfilers代理已附加。 10-12 19:11:22.828 16464-16464/com.example.vaibhav.webcontentintro W/webcontentintr:DexFile/data/user/0/com.example.vaibhav.webcontentintro/perfa.jar位于引导类路径中,但不在已知位置 10-12 19:11:22.843 16464-16540/com.example.vaibhav.webcontententintro V/StudioProfiler:获取事件应用程序 10-12 19:11: