我試圖創建HttpURLConnection類的自定義版本。嘗試擴展HttpURLConnection類時出錯
類現在看起來是這樣的:
package com.removed;
import java.net.HttpURLConnection;
import java.net.URL;
public abstract class MyHUC extends HttpURLConnection {
public MyHUC(URL url) {
super(url);
// TODO Auto-generated constructor stub
}
}
但是,當我打電話:
MyHUC connection = (MyHUC) url.openConnection();
我收到以下錯誤:
02-13 14:42:23.639: E/AndroidRuntime(4735): FATAL EXCEPTION: Thread-760
02-13 14:42:23.639: E/AndroidRuntime(4735): java.lang.ClassCastException: libcore.net.http.HttpURLConnectionImpl cannot be cast to com.removed.MyHUC
02-13 14:42:23.639: E/AndroidRuntime(4735): at com.removed.TVSlideActivity.DownloadFile(TVSlideActivity.java:603)
02-13 14:42:23.639: E/AndroidRuntime(4735): at com.removed.TVSlideActivity.access$9(TVSlideActivity.java:588)
02-13 14:42:23.639: E/AndroidRuntime(4735): at com.removed.TVSlideActivity$5.run(TVSlideActivity.java:337)
02-13 14:42:23.639: E/AndroidRuntime(4735): at java.lang.Thread.run(Thread.java:856)
這是推動我瘋了,我一直在網上尋找一個解決方案几個小時,現在任何專家都可以啓發我嗎?
謝謝!
非常感謝,這會好得多! 我現在唯一的問題是調用默認的「連接」和「斷開」的方法......他們是抽象的方法... 我實際上喜歡HttpURLConnection默認情況下,然後只替換幾個方法。 – Wildcopper 2013-02-13 14:50:12
@Wildcopper你以某種方式解決它? – serj 2016-11-30 14:35:57