我正在尝试使用jdom-2.0.6.jar从URL解析xml,但出现IOException:

IOException: Couldn't open "here is xml link"

那就是我在做什么:

import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.JDOMException;
import org.jdom2.input.SAXBuilder;

String myurl = "https://myfile.xml";

  SAXBuilder builder = new SAXBuilder();

  try {
        Document document =  builder.build(myurl);
        Element rootNode = document.getRootElement().getChild("myroot");
      } catch (IOException io) {
        Log.d("IOException", io.getMessage());
    } catch (JDOMException jdomex) {
        Log.d("JDOMException", jdomex.getMessage());
    }


相同的代码在Eclipse中效果很好,但在Android Studio中效果不佳。那怎么了?

最佳答案

我没有日志(android.os.NetworkOnMainThreadException)异常,但是在使用此solution之后,我终于解析了xml。

08-05 14:51