BufferedReader readLine未使用HttpURLConnection到达流的末尾

时间:2018-06-14 01:36:56

标签: java android httpurlconnection bufferedreader

我正在尝试从网站下载html,我尝试了两种不同的方式。每次InputStreamReader或BufferReader停在同一个地方时我都无法找出原因。

IDE:使用API​​ 28的Android Studio

<div class="title">Lista:</div>
        <div class
06-14 01:02:20.745 10602-10602/com.example.heato.guessthatcelebrity I/Length: 55847
06-14 01:02:20.769 10602-10602/com.example.heato.guessthatcelebrity D/OpenGLRenderer: Skia GL Pipeline
06-14 01:02:20.843 10602-10629/com.example.heato.guessthatcelebrity I/ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0
06-14 01:02:20.844 10602-10629/com.example.heato.guessthatcelebrity I/ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasHDRDisplay retrieved: 0
06-14 01:02:20.844 10602-10629/com.example.heato.guessthatcelebrity I/OpenGLRenderer: Initialized EGL, version 1.4
06-14 01:02:20.844 10602-10629/com.example.heato.guessthatcelebrity D/OpenGLRenderer: Swap behavior 1
06-14 01:02:20.844 10602-10629/com.example.heato.guessthatcelebrity W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
06-14 01:02:20.844 10602-10629/com.example.heato.guessthatcelebrity D/OpenGLRenderer: Swap behavior 0
06-14 01:02:20.853 10602-10629/com.example.heato.guessthatcelebrity D/EGL_emulation: eglCreateContext: 0xeadc0920: maj 3 min 1 rcv 4
06-14 01:02:20.890 10602-10629/com.example.heato.guessthatcelebrity D/EGL_emulation: eglMakeCurrent: 0xeadc0920: ver 3 1 (tinfo 0xe3695500)
06-14 01:02:20.891 10602-10629/com.example.heato.guessthatcelebrity E/eglCodecCommon: glUtilsParamSize: unknow param 0x000082da
glUtilsParamSize: unknow param 0x000082da
06-14 01:02:20.972 10602-10629/com.example.heato.guessthatcelebrity D/EGL_emulation: eglMakeCurrent: 0xeadc0920: ver 3 1 (tinfo 0xe3695500)

这是我的Logcat在流的结尾之前开始的两行,它突然停止了:

from xgboost import XGBClassifier, plot_importance
model = XGBClassifier()
model.fit(train, label)

我用Google搜索并用Google搜索,直到我的Google员工感到疼痛...任何帮助都会非常感激。是的,这是我试图遵循的教程,我尽我所能,不要让我对看似无法解释的错误感到焦虑和不安全,这让我无法学习如何编程!!

3 个答案:

答案 0 :(得分:0)

尝试记录例外:

// in graphics

if (delayTimer == 0 && targetable && bossHP > 0){
            for (int i = 0; i < 8; i++) {
                bossShotsX.add(bossX + 115 - 15);
                bossShotsY.add(bossY + 115 - 15);
                bossShotsHitBox.add(DemonBoss.drawDemonBossShotsHitBox(g, 
bossShotsY.get(bossShotsY.size() - 1) + 15, bossShotsX.get(bossShotsX.size() - 1) + 15, bossShotType));
                bossShotsDirection.add((i % 8));
                }
        }

        for (int i = 0; i < bossShotsX.size(); i++) {

        DemonBoss.drawDemonBossShots(g, bossShotsX.get(i) + 15, bossShotsY.get(i) + 15, bossShotType, bossPhase);

        }
        g.setColor(Color.BLACK);
        g.fillRect(bossX + 114,bossY + 114, 2, 2);       
// in action performed method
Rectangle playerHitBox = new Rectangle (p1X, p1Y, 50, 100);
    Rectangle bossHitBox = new Rectangle(bossX + 50, bossY, 130, 230);

    // boss shoot stuff
            for (int i = 0; i < bossShotsHitBox.size(); i++) {
                int xChange = 0, yChange = 0;
                if (bossShotsDirection.get(i) == N) {
                    yChange = -bossShotSpeed;
                }
                if (bossShotsDirection.get(i) == NE) {
                    yChange = -bossShotSpeed;
                    xChange = bossShotSpeed;
                }
                if (bossShotsDirection.get(i) == E) {
                    xChange = +bossShotSpeed;
                }
                if (bossShotsDirection.get(i) == SE) {
                    yChange = bossShotSpeed;
                    xChange = bossShotSpeed;
                    }
                if (bossShotsDirection.get(i) == S) {
                    yChange = bossShotSpeed;
                }
                if (bossShotsDirection.get(i) == SW) {
                    yChange = bossShotSpeed;
                    xChange = -bossShotSpeed;
                    }
                if (bossShotsDirection.get(i) == W) {
                    xChange = -bossShotSpeed;
                }
                if (bossShotsDirection.get(i) == NW) {
                    yChange = -bossShotSpeed;
                    xChange = -bossShotSpeed;
                }
               bossShotsX.set(i, bossShotsX.get(i) + xChange);
               bossShotsY.set(i, bossShotsY.get(i) + yChange);
               bossShotsHitBox.set(i, new Rectangle(bossShotsX.get(i), bossShotsY.get(i), 30, 30));   

        if (playerHitBox.intersects(bossShotsHitBox.get(i))){
            if (bossShotType == 1) {
            P1_HP -= 30;
            }
            bossShotsHitBox.remove(i);  
            bossShotsX.remove(i);
            bossShotsY.remove(i);
            bossShotsDirection.remove(i);
        }

        if (bossShotsX.get(i)  <= 0 ||
            bossShotsX.get(i)  >= 1000 ||
            bossShotsY.get(i)  <= 0 ||
            bossShotsY.get(i)  >= 1000) {
            bossShotsX.remove(i);
            bossShotsY.remove(i);
            bossShotsHitBox.remove(i);
            bossShotsDirection.remove(i);
        }
    }

Log.e(MainActivity.class.getSimpleName(), "Request failed", e); 的输出未在任何地方捕获。

答案 1 :(得分:0)

这是因为logcat消息的长度有限,而且过长的消息将被截断。使用adb logcat -g检查限制:

$ adb logcat -g
main: ring buffer is 256Kb (254Kb consumed), max entry is 5120b, max payload is 4068b
system: ring buffer is 256Kb (242Kb consumed), max entry is 5120b, max payload is 4068b
crash: ring buffer is 256Kb (3Kb consumed), max entry is 5120b, max payload is 4068b

在你的情况下,似乎你的html字符串(Log.i("Length", "" + html.length());)的长度是正确的,所以问题只是关于logcat的输出,你可以通过将字符串保存到文件来检查完整的字符串,或者拆分串成小片。

答案 2 :(得分:0)

  

result = task.execute(url).get();

使用.get()语句非常糟糕。

删除它。

你的结果将在onPostExecute()中提供,所以在那里处理结果。