如何调试一个简单的网站字符串抓取器

时间:2012-09-05 10:13:19

标签: java debugging

有没有人对如何更好地调试这个有任何建议?我知道它在line = in.readLine()返回null,即使它不应该。我加了一层throwables,但不幸的是,没有错误被打印出来。我有什么建议可以接下来试试吗?

public static String pullString(int id) throws IOException {

    String price;
    logError("Checkpoint 1");
    URL url = new URL("http://www.example.com");
    URLConnection con = url.openConnection();
    logError("Checkpoint 2");
    BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
    logError("Checkpoint 3");
    String line;

    while ((line = in.readLine()) != null) {
    //^ for some reason this becomes null, but on identical pages it works fine. 


          //Removed unneeded info


                return ---;
            } catch (NumberFormatException e) {
                logError("NumberFormatException");

                return null;
            }
        }
    }
    logError("left out the back");
    return null;
}

0 个答案:

没有答案