簡體   English   中英

MalformedURLException的

[英]MalformedURLException

這是一種將頁面源代碼轉換為字符串數組並返回該數組的方法,但是由於某些原因,我一直會遇到異常錯誤。

當我嘗試使用此類時,它將返回我java.net.MalformedURLException:無協議

我已經處理了異常,但我不明白。 有人可以向我解釋為什么我繼續收到此錯誤嗎?

 public static String[] Connect(String A) throws IOException,
    MalformedURLException {
    ArrayList<String> myList = new ArrayList<String>();
    URL url = new URL("A");
    URLConnection spoof = url.openConnection();


    spoof.setRequestProperty( "User-Agent", "Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0; H010818)" );
    BufferedReader in = new BufferedReader(new InputStreamReader(spoof.getInputStream()));
    String strLine = "";

    while ((strLine = in.readLine()) != null){
        myList.add(strLine);
        System.out.println(strLine);
    }
    String[] arr = myList.toArray(new String[myList.size()]);
    return arr;

}

您將字符串"A"作為參數傳遞給URL構造函數new URL("A"); "A"不是有效的網址。 我想您打算將其傳遞給變量A,對不對? 刪除" "

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM