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

标签 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 US Dollar = 45.92697 Indian Rupee
45.92697

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

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

干杯!

关于java - DocumentBuilder.parse(String Uri) 正在返回 IOException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4306981/

相关文章:

java - 此客户端服务器通信模型的跨语言 API

java - Java 反编译器如何区分 for 循环和 while 循环?

java - 到根文件夹的最快/最短途径?

java - Ajax 响应中的 Set-Cookie header 不适用于 android webView

java - 如何为 Android 自定义 View 添加 OnClick 事件

java - 无法使用 JUnit 4.11 捕获带有 ExpectedException 的 UnrecognizedPropertyException

java - 有没有办法使用 Jackson 的 ObjectMapper 来序列化流?

java.lang.runtimeexception 无法实例化接收器

Android: toast 消息消失后​​如何关闭应用程序?

java - 对服务器套接字客户端使用 Executor 而不是新线程