我在SD卡上創建了一個空白的.xml文件,現在我試圖打開它進行解析。無法打開xml文件解析SD卡
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
Document newDoc = docBuilder.parse(xmlFile);
當它到達parse()方法得到以下的logcat:
03-11 12:07:20.676: E/Exception(18774): org.xml.sax.SAXParseException: Unexpected end of document
03-11 12:07:20.676: E/Exception(18774): at org.apache.harmony.xml.parsers.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:131)
03-11 12:07:20.676: E/Exception(18774): at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:186)
03-11 12:07:20.676: E/Exception(18774): at mfc.generalguixapi8.SaveData4.saveData(SaveData4.java:76)
03-11 12:07:20.676: E/Exception(18774): at mfc.generalguixapi8.SaveData4.onCreate(SaveData4.java:40)
03-11 12:07:20.676: E/Exception(18774): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-11 12:07:20.676: E/Exception(18774): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
03-11 12:07:20.676: E/Exception(18774): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
03-11 12:07:20.676: E/Exception(18774): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
03-11 12:07:20.676: E/Exception(18774): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
03-11 12:07:20.676: E/Exception(18774): at android.os.Handler.dispatchMessage(Handler.java:99)
03-11 12:07:20.676: E/Exception(18774): at android.os.Looper.loop(Looper.java:123)
03-11 12:07:20.676: E/Exception(18774): at android.app.ActivityThread.main(ActivityThread.java:4627)
03-11 12:07:20.676: E/Exception(18774): at java.lang.reflect.Method.invokeNative(Native Method)
03-11 12:07:20.676: E/Exception(18774): at java.lang.reflect.Method.invoke(Method.java:521)
03-11 12:07:20.676: E/Exception(18774): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
03-11 12:07:20.676: E/Exception(18774): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
03-11 12:07:20.676: E/Exception(18774): at dalvik.system.NativeStart.main(Native Method)
什麼是你需要解析一個空白文件?例外說該文件不是一個合適的XML文件。 – Egor 2012-03-11 12:24:14
@Neeta:首先驗證你的XML文件使用任何XML驗證,如[xmlvalidation](http://www.xmlvalidation.com/) – 2012-03-11 12:29:31
@Egor我想添加更多的XML到文件。也許我需要寫入XML文件後,我已經做了一個DOM,我想追加? – Neeta 2012-03-11 12:31:43