我有以下類:如何通過url獲取xml(AsyncTask,android)?
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
XmlManager xm = new XmlManager();
Log.i("tag",documentToString(xm.getXmlFromUrl("http://domen.com/abc/timelist.xml")));
}
//................
}
public class XmlManager {
public Document getXmlFromUrl(String url) {
GetXmlTask txt = new GetXmlTask();
txt.execute(url);
Document doc = null;
try {
doc = txt.get(5, TimeUnit.SECONDS);
Log.i("tag", "test");
}
catch (Exception e) {
e.printStackTrace();
}
return doc;
}
//................
}
public class GetXmlTask extends AsyncTask<String, Void, org.w3c.dom.Document> {
@Override
protected Document doInBackground(String... arg0) {
String url = "";
if(arg0.length > 0){
url = arg0[0];
}
Document doc = null;
try {
doc = stringToDom(convertStreamToString(new URL(url).openStream()));
}
catch (Exception e) {
e.printStackTrace();
}
return doc;
}
//................
}
不幸的是,我不明白的地方存在錯誤。我在logcat中看到(沒有過濾器):
01-24 17:47:44.194:W /合子(37):預裝繪製資源 與配置而有所不同!! 01-24 17:47:44.204:W /合子(37): 預裝繪製資源#0x1080446 (RES /抽拉-MDPI/popup_inline_error_above_holo_light.9.png),其與 配置而變化! 01-24 17:47:44.284:W/Zygote(37): 預裝的可繪製資源#0x1080447 (res/drawable-mdpi/popup_inline_error_holo_dark.9.png),其配置變化爲 ! 01-24 17:47:44.294:W/Zygote(37):預加載 可繪製資源#0x1080448 (res/drawable-mdpi/popup_inline_error_holo_light.9.png)變化 配置! 01-24 17:47:46.315:W/Zygote(37):預加載 drawable資源#0x10802ec (res/drawable-mdpi/ic_lockscreen_outerring.png)隨 配置而變化! 01-24 17:47:48.644:A/BatteryStatsImpl(93): libcore.io.ErrnoException:打開失敗:ENOENT(沒有這樣的文件或目錄 )01-24 17:47:48.714:E/AndroidRuntime致(93):錯誤報告 WTF 01-24 17:47:48.714:E/AndroidRuntime(93):在 android.util.Log $ 1.onTerribleFailure(Log.java:103)01-24 17:47:56.774: E /的Soundpool(93):錯誤裝載/system/media/audio/ui/Lock.ogg 01-24 17:47:56.774:E /的Soundpool(93):錯誤裝載 /系統/媒體/音頻/ UI /Unlock.ogg 01-24 17:48:03.064: W/NetworkManagementSocketTagger(93):setKernelCountSet(10005,1) 失敗,錯誤號-2 01-24 17:48:11.094:d/StrictMode(190):在 com.android.internal.telephony.gsm.SpnOverride.loadSpnOverrides(SpnOverride .java:61) 01-24 17:48:11.094:D/StrictMode(190):at com.android.internal.telephony.gsm.SpnOverride。(SpnOverride.java:43) 01-24 17:48 :12.592:E/SoundPool(93):錯誤加載 /system/media/audio/ui/Effect_Tick.ogg 01-24 17:48:12.592: E/SoundPool(93):error loading/system/media/audio /ui/Effect_Tick.ogg 01-24 17:48:12.592:E/SoundPool(93):錯誤加載 /system/media/audio/ui/Effect_Tick.ogg 01-24 17:48:12.592: E /的Soundpool(93):錯誤裝載/system/media/audio/ui/Effect_Tick.ogg 01-24 17:48:12.592:E /的Soundpool(93):錯誤裝載 /系統/媒體/音頻/ UI/Effect_Tick。 ogg 01-24 17:48:12.592: E/SoundPool(93):錯誤加載 /system/media/audio/ui/KeypressStandard.ogg 01-24 17:48:12.592: E /的Soundpool(93):錯誤裝載 /system/media/audio/ui/KeypressSpacebar.ogg 01-24 17: (93):錯誤加載 /system/audio /媒體/音頻/ UI/KeypressReturn.ogg 01-24 17:48:12.982: W/AudioService(93):loadSoundEffects(),錯誤-1而裝載樣品 01-24 17:48:20.262:A/NetworkStats( 93):導致: libcore.io.ErrnoException:打開失敗:ENOENT(沒有這樣的文件或 目錄)01-24 17:48:24.822:D/StrictMode(190):在 com.android.internal.telephony .gsm.GsmDataConnectionTrack er.getPreferredApn(GsmDataConnectionTracker.java:2276) 01-24 17:48:28.822:A/NetworkStats(93):引起者: libcore.io。ErrnoException:打開失敗:ENOENT(無此文件或 目錄)01-24 17:48:30.883:D/MmsSmsDatabaseHelper(190):[MmsSmsDb] hasAutoIncrement:CREATE TABLE threads(_id INTEGER PRIMARY KEY AUTOINCREMENT,date INTEGER DEFAULT 0,message_count INTEGER DEFAULT 0,recipient_ids TEXT,snippet TEXT,snippet_cs INTEGER DEFAULT 0,讀取 INTEGER DEFAULT 1,類型INTEGER DEFAULT 0,錯誤INTEGER DEFAULT 0,has_attachment INTEGER DEFAULT 0)result:true 01-24 17:48 :38.492: W/MediaScanner(412):錯誤打開目錄 '/mnt/sdcard/.android_secure/',跳過:權限被拒絕。 01-24 17:48:44.462:I/ActivityManager(93):啓動proc com.svox.pico for broadcast com.svox.pico/.VoiceDataInstallerReceiver:pid = 541 uid = 10024 gids = {1015} 01- 24:17:48:51.142:W/NetworkManagementSocketTagger(93): setKernelCountSet(10041,1)失敗,並且errno -2 01-24 17:48:55.792: W/NetworkManagementSocketTagger(93):setKernelCountSet(10005,0) errno失敗-2
按應用程序名稱篩選: LogCat中存在空白。
過濾器的標籤 「標籤」:
01-24 17:48:03.064:W/NetworkManagementSocketTagger(93): setKernelCountSet(10005,1)失敗,錯誤號-2 01-24 17: 48:51.142: W/NetworkManagementSocketTagger(93):setKernelCountSet(10041,1) 失敗,錯誤號-2 01-24 17:48:55.792: W/NetworkManagementSocketTagger(93):setKernelCountSet(10005,0) 失敗errno -2
非常感謝! – Denis
@Denis您的歡迎。 –