2012-06-11 91 views
0

有幾個職位重新:這個主題,但無法弄清楚爲什麼這將無法正常工作。 繼續收到IOException。猜測它找不到該文件。乾杯。IO異常尋找在Android中使用DOM的文件路徑

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 
DocumentBuilder builder = factory.newDocumentBuilder(); 
Document doc = builder.parse("//res/xml/xml_data.xml"); 

回答

1

改變你的這個

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 
DocumentBuilder builder = factory.newDocumentBuilder(); 
Document doc = builder.parse("res/xml/xml_data.xml"); 
+1

好一點,你的解決方案似乎比我更好,無論如何。 – FoamyGuy

+0

謝謝,我知道它(XmlResourceParser),因爲我曾經使用它。 – Sajmon

1

您的網址不正確。資源的形式是:

"android.resource://[package]/[res type]/[res name]" 

"android.resource://[package]/[res id] 

"android.resource://com.org.example/xml/xml_data" // No extension 

"android.resource://com.org.example/" + R.xml.xml_data 
+0

謝謝,但我不斷收到錯誤... W/System.err(332):java.net.MalformedURLException:未知的協議:android.resource ...所以仍然問題與文件路徑試圖使用DOM讀入xml文件。任何建議都會很棒。乾杯。 – jmg