我正在尝试解析桌面上的xml文件。我收到了一个错误

时间:2011-03-29 06:51:08

标签: android

解析代码是:

private UrlList parseUrl(URL url) {
    URL SourceUrl = null;
    SourceUrl = url;

    try {
        /** Handling XML */
        SAXParserFactory spf = SAXParserFactory.newInstance();
        SAXParser sp = spf.newSAXParser();
        XMLReader xr = sp.getXMLReader();
        /** Create handler to handle XML Tags ( extends DefaultHandler ) */
        XMLParser myXmlParser = new XMLParser();
        xr.setContentHandler(myXmlParser);
        xr.parse(new InputSource(SourceUrl.openStream()));

    } catch (IOException e) {
        e.printStackTrace();
    } catch (Exception e) {
        System.out.println(" XMLParsing error is : " + e);
    }

    urlList = XMLParser.urlList;
    return urlList;
}// end of parseurl

我给的网址是 sourceUrl =新网址(“file:// C:/Users/raghu/Desktop/aero/products.xml”); 类似地,我也以相同的方式拥有资源路径

file://C:/Users/raghu/Desktop/aero/"resource sub folders"

我收到以下错误

     D/dalvikvm(  118): GC_EXPLICIT freed 80K, 52% free 2864K/5895K, external 2155K/2537K, paused 82ms
W/System.err( 1078): java.io.IOException: Unable to connect to server: null
W/System.err( 1078):    at org.apache.harmony.luni.internal.net.www.protocol.ftp.FtpURLConnection.connect(FtpURLConnection.java:203)
W/System.err( 1078):    at org.apache.harmony.luni.internal.net.www.protocol.ftp.FtpURLConnection.getInputStream(FtpURLConnection.java:300)
W/System.err( 1078):    at java.net.URL.openStream(URL.java:645)
W/System.err( 1078):    at com.omkarsoft.ImagePortofolio.ImagePortofolio.parseUrl(ImagePortofolio.java:178)
W/System.err( 1078):    at com.omkarsoft.ImagePortofolio.ImagePortofolio.onCreate(ImagePortofolio.java:76)
W/System.err( 1078):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
W/System.err( 1078):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
W/System.err( 1078):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
W/System.err( 1078):    at android.app.ActivityThread.access$1500(ActivityThread.java:117)
W/System.err( 1078):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
W/System.err( 1078):    at android.os.Handler.dispatchMessage(Handler.java:99)
W/System.err( 1078):    at android.os.Looper.loop(Looper.java:123)
W/System.err( 1078):    at android.app.ActivityThread.main(ActivityThread.java:3683)
W/System.err( 1078):    at java.lang.reflect.Method.invokeNative(Native Method)
W/System.err( 1078):    at java.lang.reflect.Method.invoke(Method.java:507)
W/System.err( 1078):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
W/System.err( 1078):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)

1 个答案:

答案 0 :(得分:2)

您需要将文件推送到Android模拟器文件系统。例如

adb push C:/Users/raghu/Desktop/aero/products.xml /sdcard/products.xml

并使用后一条路径。