您好,我正在尝试获取rss源,代码如下:
try {
URL url = new URL("http://investing_api.ambcrypto.com/feed/cryptolab/");
InputStream inputStream = url.openConnection().getInputStream();//error in this line
ArrayList<NewsModel> items = parseFeed(inputStream);
return items;
} catch (IOException e) {
e.printStackTrace();
} catch (XmlPullParserException e) {
e.printStackTrace();
}
它由和AsyncTask包装,我得到了这个日志:
07-22 23:23:03.090 11728-12314/com.mal.saul.coinmarketcap W/System.err: java.net.UnknownHostException: http://investing_api.ambcrypto.com/feed/cryptolab/
07-22 23:23:03.095 11728-13197/com.mal.saul.coinmarketcap I/FirebasePerformance: URL host is null or invalid
Unable to process an HTTP request/response due to missing or invalid values. See earlier log statements for additional information on the specific invalid/missing values.
07-22 23:23:03.110 11728-12314/com.mal.saul.coinmarketcap W/System.err: at libcore.net.http.HttpConnection$Address.<init>(HttpConnection.java:282)
07-22 23:23:03.120 11728-12314/com.mal.saul.coinmarketcap W/System.err: at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
有人知道吗?我也试过google news rss feed(https://news.google.com/news/rss/headlines/section/topic/WORLD?ned=us
方法parseFeed():
public ArrayList<NewsModel> parseFeed(InputStream inputStream) throws XmlPullParserException,
IOException {
String title = null;
String link = null;
String imageUrl = null;
long pubDate = 0;
boolean isItem = false;
ArrayList<NewsModel> items = new ArrayList<>();
try {
XmlPullParser xmlPullParser = Xml.newPullParser();
xmlPullParser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false);
xmlPullParser.setInput(inputStream, null);
xmlPullParser.nextTag();
while (xmlPullParser.next() != XmlPullParser.END_DOCUMENT) {
int eventType = xmlPullParser.getEventType();
String name = xmlPullParser.getName();
if(name == null)
continue;
if(eventType == XmlPullParser.END_TAG) {
if(name.equalsIgnoreCase("item")) {
isItem = false;
}
continue;
}
if (eventType == XmlPullParser.START_TAG) {
if(name.equalsIgnoreCase("item")) {
isItem = true;
continue;
}
}
Log.d("MyXmlParser", "Parsing name ==> " + name);
String result = "";
if (xmlPullParser.next() == XmlPullParser.TEXT) {
result = xmlPullParser.getText();
xmlPullParser.nextTag();
}
if (name.equalsIgnoreCase("title")) {
title = result;
} else if (name.equalsIgnoreCase("link")) {
link = result;
} else if (name.equalsIgnoreCase("url url")) {
imageUrl = result;
} else if (name.equalsIgnoreCase("pubDate")) {
pubDate = Long.parseLong(result);
}
if (title != null && link != null && imageUrl != null && pubDate != 0) {
if(isItem) {
NewsModel newsModel = new NewsModel();
newsModel.setPostTitle(title);
newsModel.setPostUrl(link);
newsModel.setPubDate(pubDate);
items.add(newsModel);
}
title = null;
link = null;
imageUrl = null;
isItem = false;
pubDate = 0;
}
}
return items;
} finally {
inputStream.close();
}
}
检查您的API url它需要一些值。
在AWS EC2 T2上部署停靠的Spring Boot应用程序时,我遇到了这个“java.net.UnknownHostException:host.docker.internal:Name或service not known”问题。微实例。由于此错误,spring启动应用程序无法启动。 但奇怪的是,我没有在应用程序的任何地方使用变量“host.docker.internal”:不在代码中,不在
问题内容: 我正在尝试通过android应用程序中的HTTP Post请求访问textalertapp.com。但是我收到了未知主机错误。谁能帮我解决这个问题。 代码是 问题答案: 我只是在清单文件中添加了这一行。问题解决了
我的机器运行的是hbase-0.94.16服务器,因此当我尝试使用hbase definitive primitive guide中的文档来安装hbase hush服务器时,它出现了以下异常 14/05/22 11:03:43信息zookeeper.zookeeper:客户端环境:java.io.tmpdir=/tmp 14/05/22 11:03:43信息zookeeper.zookeeper:
我使用的是Spring版本-2.4.5 pplication.properties: 所有依赖项都已正确导入。 POM。xml 但在点击api网关时仍面临以下错误: http://localhost:8765/currency-兑换/货币兑换/自/美元/至/印度卢比(或) http://localhost:8765/CURRENCY-兑换/货币兑换/自/美元/至/印度卢比
我在JMeter上运行测试脚本时遇到过这种错误? java.net.unknownHostException:h2ebiz-testat java.net.inet6addressimpl.lookupAllHostAddr(本机方法)位于java.net.inetAddress.2.lookupAllHostAddr(未知源)位于java.net.inetAddress.getAddress.g
我一直在致力于实现ServletWrappingController方法,我遇到了一些问题。这是我的配置。。。 我有几个例外... 严重:上下文初始化失败。springframework。豆。工厂BeanCreationException:创建名为“urlMapping”的bean时出错,该bean在ServletContext资源[/WEB-INF/dispatcher servlet.xml]