DocumentBuilder.parse(String Uri)正在返回IOException

时间:2010-11-29 18:50:57

标签: java android

package com.converter;

import java.io.IOException;
import java.net.URI;
import java.net.URL;

import java.util.StringTokenizer;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;

import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXParseException;
//import XmlReader.java;
public class XMLReader {
 public  Float value = 25f;

public XMLReader(){
 String parseString = "";


 try { 

    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
  //  dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
    DocumentBuilder db = dbf.newDocumentBuilder();  
    URI uri = new URI("http://themoneyconverter.com/USD/rss.xml");

    ****Document doc = db.parse(uri.toString());****      

    doc.getDocumentElement().normalize();  
   NodeList nodeLst = doc.getElementsByTagName("description");
   int length = nodeLst.getLength(); 

    for (int s = 0; s < length; s++) {
     Node fstNode = nodeLst.item(s);   
     parseString = fstNode.getTextContent();

     if(parseString.contains("Indian Rupee")){
      System.out.println(parseString);
      StringTokenizer parser = new StringTokenizer(parseString,"=");
      parser.nextToken();
      StringTokenizer parser1 = new StringTokenizer(parser.nextToken());    
      value = Float.valueOf(parser1.nextToken());
      System.out.println(value);

     }  

    }
    } catch (SAXParseException e) {
     value = 30f;
      e.printStackTrace();
    }catch (IOException e) {
     value = 33f;
       e.printStackTrace();
   }catch (Exception e) {
      value = 32f;
      e.printStackTrace();
   }

}

}

1 个答案:

答案 0 :(得分:1)

这个正在为我输出:

1 US Dollar = 45.92697 Indian Rupee
45.92697

所以我猜你在访问资源时遇到了一些网络问题。检查防火墙设置,防病毒程序等。

如果您需要更多帮助,也可以在此处粘贴堆栈跟踪;)

干杯!