- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在为我在 uni 的最后一年项目创建一个应用程序。我正在尝试让 rss 提要工作。我目前的问题是我创建了一个项目 (RSSActivity) 并让 RSS 提要工作。然后我将所有文件(5 个类和 2 个布局)复制并粘贴到适当的位置。有一些错误:找不到 R,但是通过将包更改为项目 (football_app) 的包很容易修复。我想做的是能够点击一个名为“新闻”的按钮,新闻就会出现。我遇到的问题是,当我现在点击“新闻”按钮时,它说“不幸的是足球应用程序”已经停止'..我已经尝试了 Intent 中的每个类,并适本地更改了 Intent Activity 名称..任何人都可以帮助我..下面的代码......
/////////////// HttpFeedSource.java
package com.julian.football_app;
import java.util.ArrayList;
import java.util.List;
class HttpFeedSource implements FeedSource {
protected static final String URL = "http://www.skysports.com/rss/0,20514,11661,00.xml";
public List<RSSItem> getFeed() {
List<RSSItem> itemList = new ArrayList<RSSItem>();
NewsParser parser = new NewsParser(URL);
parser.parse();
NewsParser.RssFeed feed = parser.getFeed();
for (NewsParser.Item i : feed.getItems()) {
itemList.add(new RSSItem(i.getUrl(), i.getTitle(), i.getDescription(), i.getimageUrl()));
}
return itemList;
}
}
////////////////////// FeedSource.java
package com.julian.football_app;
import java.util.List;
interface FeedSource {
List<RSSItem> getFeed();
}
<code>
/////////////////////////////////////////////////////////////////////////////////////MockFeedSource.java
包 com.julian.football_app;
导入java.util.ArrayList;导入 java.util.List;
类 MockFeedSource 实现 FeedSource {
public List<RSSItem> getFeed() {
RSSItem item;
final List<RSSItem> items = new ArrayList<RSSItem>();
item = new RSSItem("Android Workshop er gøy", "http://www.ap.no", " this is the desc", "");
items.add(item);
item = new RSSItem("Android Workshop er gøy 2", "http://www.ap.no", "this is the desc", "");
items.add(item);
item = new RSSItem("Android Workshop er gøy3", "http://www.ap.no", "this is the desc", "");
items.add(item);
return items;
}
</code>
/////////////////////////////////////////////////////////////////////////////////////////// NewsParser.java
package com.julian.football_app;
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.helpers.DefaultHandler;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import java.io.InputStream;
import java.net.URL;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;
class NewsParser extends DefaultHandler {
public static SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.ENGLISH);
private String urlString;
private RssFeed rssFeed;
private StringBuilder text;
private Item item;
private boolean imgStatus;
public NewsParser(String url) {
this.urlString = url;
this.text = new StringBuilder();
}
public void parse() {
InputStream urlInputStream = null;
SAXParserFactory spf;
SAXParser sp;
try {
URL url = new URL(this.urlString);
urlInputStream = url.openConnection().getInputStream();
InputSource is = new InputSource(urlInputStream);
is.setEncoding("ISO-8859-1");
spf = SAXParserFactory.newInstance();
if (spf != null) {
sp = spf.newSAXParser();
sp.parse(is, this);
}
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
try {
if (urlInputStream != null) urlInputStream.close();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
public RssFeed getFeed() {
return (this.rssFeed);
}
public void startElement(String uri, String localName, String qName,
Attributes attributes) {
if (qName.equalsIgnoreCase("channel"))
this.rssFeed = new RssFeed();
else if (qName.equalsIgnoreCase("item") && (this.rssFeed != null)) {
this.item = new Item();
this.rssFeed.addItem(this.item);
} else if (qName.equalsIgnoreCase("image") && (this.rssFeed != null))
this.imgStatus = true;
}
public void endElement(String uri, String localName, String qName) {
if (this.rssFeed == null)
return;
if (qName.equalsIgnoreCase("item"))
this.item = null;
else if (qName.equalsIgnoreCase("image"))
this.imgStatus = false;
else if (qName.equalsIgnoreCase("title")) {
if (this.item != null) this.item.title = this.text.toString().trim();
else if (this.imgStatus) this.rssFeed.imageTitle = this.text.toString().trim();
else this.rssFeed.title = this.text.toString().trim();
} else if (qName.equalsIgnoreCase("link")) {
if (this.item != null) this.item.link = this.text.toString().trim();
else if (this.imgStatus) this.rssFeed.imageLink = this.text.toString().trim();
else this.rssFeed.link = this.text.toString().trim();
} else if (qName.equalsIgnoreCase("description")) {
if (this.item != null) this.item.description = this.text.toString().trim();
else this.rssFeed.description = this.text.toString().trim();
} else if (qName.equalsIgnoreCase("url") && this.imgStatus)
this.rssFeed.imageUrl = this.text.toString().trim();
else if (qName.equalsIgnoreCase("language"))
this.rssFeed.language = this.text.toString().trim();
else if (qName.equalsIgnoreCase("generator"))
this.rssFeed.generator = this.text.toString().trim();
else if (qName.equalsIgnoreCase("copyright"))
this.rssFeed.copyright = this.text.toString().trim();
else if (qName.equalsIgnoreCase("pubDate") && (this.item != null)) {
try {
this.item.pubDate = sdf.parse(this.text.toString().trim());
} catch (ParseException e) {
throw new RuntimeException();
}
} else if (qName.equalsIgnoreCase("category") && (this.item != null))
this.rssFeed.addItem(this.text.toString().trim(), this.item);
this.text.setLength(0);
}
public void characters(char[] ch, int start, int length) {
this.text.append(ch, start, length);
}
public static class RssFeed {
public String title;
public String description;
public String link;
public String language;
public String generator;
public String copyright;
public String imageUrl;
public String imageTitle;
public String imageLink;
private ArrayList<Item> items;
private HashMap<String, ArrayList<Item>> category;
public void addItem(Item item) {
if (this.items == null)
this.items = new ArrayList<Item>();
this.items.add(item);
}
public void addItem(String category, Item item) {
if (this.category == null)
this.category = new HashMap<String, ArrayList<Item>>();
if (!this.category.containsKey(category))
this.category.put(category, new ArrayList<Item>());
this.category.get(category).add(item);
}
public ArrayList<Item> getItems() {
return items;
}
}
public static class Item implements Comparable<Item> {
public String title;
public String description;
public String link;
public Date pubDate;
private String url;
private String imageUrl;
public String toString() {
return (this.title + ": ");
}
public int compareTo(Item o) {
return (int) (o.pubDate.getTime() - pubDate.getTime());
}
public Date getPubDate() {
return pubDate;
}
public String getDescription() {
return description;
}
public String getTitle() {
return title;
}
public String getUrl() {
return url;
}
public String getimageUrl() {
return imageUrl;
}
}
}
package com.julian.football_app;
import com.julian.football_app.R;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ListView;
public class RSSActivity extends Activity {
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main2);
ListView rssItemList = (ListView) findViewById(R.id.rssListview);
FeedSource feedSource = new HttpFeedSource();
RSSItemAdapter adapter = new RSSItemAdapter(this, R.layout.rssitem, feedSource.getFeed());
rssItemList.setAdapter(adapter);
}
}
/////////RssItem
package com.julian.football_app;
import java.util.Date;
class RSSItem {
private String url;
private String title;
private String description;
private String imageUrl;
private Date pubDate;
public RSSItem() {
}
public RSSItem(String url, String title, String description, String imageUrl) {
this.url = url;
this.title = title;
this.description = description;
this.imageUrl = imageUrl;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDesc(String description) {
this.description = description;
}
public void setImageUrl(String imageUrl) {
this.imageUrl = imageUrl;
}
public String getimageUrl() {
return imageUrl;
}
public void setpubDate(Date pubDate){
this.pubDate = pubDate;
}
public Date getpubDate(){
return pubDate;
}
}
////////////////// RssItemAdaptor
package com.julian.football_app;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import java.util.List;
import com.julian.football_app.R;
class RSSItemAdapter extends ArrayAdapter<RSSItem> {
private final Context context;
public RSSItemAdapter(Context context, int textViewResourceId,
List<RSSItem> items) {
super(context, textViewResourceId, items);
this.context = context;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater vi = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.rssitem, null);
}
final RSSItem item = getItem(position);
TextView title = (TextView) v.findViewById(R.id.title);
TextView desc = (TextView) v.findViewById(R.id.description);
TextView url = (TextView) v.findViewById(R.id.url);
// this is what is viewed
title.setText(item.getTitle());
desc.setText(item.getDescription());
url.setText(item.getimageUrl());
return v;
}
}
///This is the button i want to display the Rss Feed
package com.julian.football_app;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class Menu extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.menu);
//setting the buttons
Button btnews1 = (Button) findViewById(R.id.news_1);
btnews1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
Intent news1intent = new Intent(Menu.this, news_1.class);
Menu.this.startActivity(news1intent);
}
});
感谢您查看我的代码...如果有人能帮助我,我将不胜感激 :)(我知道它的 Intent 是说 news_1.class.. 唯一的原因是我尝试了一切并回到了原始状态..)
这些是出现在 LogCat 中的错误:
03-23 13:54:16.118: E/AndroidRuntime(553): FATAL EXCEPTION: main
03-23 13:54:16.118: E/AndroidRuntime(553): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1508)
03-23 13:54:16.118: E/AndroidRuntime(553): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1384)
03-23 13:54:16.118: E/AndroidRuntime(553): at android.app.Activity.startActivityForResult(Activity.java:3190)
03-23 13:54:16.118: E/AndroidRuntime(553): at android.app.Activity.startActivity(Activity.java:3297)
03-23 13:54:16.118: E/AndroidRuntime(553): at com.julian.football_app.Menu$1.onClick(Menu.java:24)
03-23 13:54:16.118: E/AndroidRuntime(553): at android.view.View.performClick(View.java:3460)
03-23 13:54:16.118: E/AndroidRuntime(553): at android.view.View$PerformClick.run(View.java:13955)
03-23 13:54:16.118: E/AndroidRuntime(553): at android.os.Handler.handleCallback(Handler.java:605)
03-23 13:54:16.118: E/AndroidRuntime(553): at android.os.Handler.dispatchMessage(Handler.java:92)
03-23 13:54:16.118: E/AndroidRuntime(553): at android.os.Looper.loop(Looper.java:137)
03-23 13:54:16.118: E/AndroidRuntime(553): at android.app.ActivityThread.main(ActivityThread.java:4340)
03-23 13:54:16.118: E/AndroidRuntime(553): at java.lang.reflect.Method.invokeNative(Native Method)
03-23 13:54:16.118: E/AndroidRuntime(553): at java.lang.reflect.Method.invoke(Method.java:511)
03-23 13:54:16.118: E/AndroidRuntime(553): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
03-23 13:54:16.118: E/AndroidRuntime(553): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
03-23 13:54:16.118: E/AndroidRuntime(553): at dalvik.system.NativeStart.main(Native Method)
最佳答案
听起来应用程序遇到了异常。要找到原因,您需要使用 LogCat 查看异常详细信息,它会告诉您代码中哪里有问题。
关于java - Android RSS 提要,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9839276/
关闭。这个问题不满足Stack Overflow guidelines .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 3年前关闭。 Improve thi
当我将 JSON 提要(Wordpress JSON 提要)解析到我的 React Native 提要页面时,我在模拟器中没有看到任何结果,以下是我正在使用的代码; ------------AppBo
我有一个网页,其中有一个搜索页面。我提供了一个用于搜索的“动态”RSS 提要,以便用户可以订阅他喜欢的任何搜索词的搜索结果。 所以我想知道如果该搜索词返回 0 个结果(这意味着我没有“项目”可放入提要
我想要测试我创建的 RSS Feed,我正在寻找一些好的 RSS Feed 应用程序来测试。 最佳答案 不要只是尝试一堆,看看它是否有效 - 验证它。让我为您谷歌一下: W3C RSS validat
我有一些 PHP 代码可以合并两个 RSS 提要。我试图按日期对提要进行排序,但我得到了一个有趣的结果: 两个 Feed 分别排序(第一个 Feed 先列出,然后第二个饲料) 第一个提要按升序排序,第
我最近开始使用“新 Google 表格”(电子表格),他们将 URL 更改为共享的公共(public)电子表格,我不确定如何获取电子表格数据的 JSON 提要。 基于来自此 URL 的数据:https
我想知道在您的应用程序中使用其他人的 RSS 提要(例如 BBC RSS 提要)是否存在任何法律问题? 最佳答案 你真的应该问律师。但是,我在 out-law.com 上找到了这个: Using a
我们有一个提供一些 RSS 提要的站点,我们想知道有多少人订阅了每个提要,而不使用像 FeedBurner 这样的系统来为他们提供服务。 解决这个问题的原始方法基本上是记录请求,然后获取请求每个提要的
我有一个系统可以获取几百个 RSS 提要。目前,它们的刷新周期为 10 分钟,但我最好让它更快。以近实时/推送间隔获取 RSS 源的策略是什么? 我遇到的一些解决方案: 1分钟取一次;如果没有变化,则
我已经开始开发一个网页,最近聘请了某人编写代码以在 http://farmball.com/ 的中间面板中显示自定义提要(由 API 提供支持)。 . 请注意,这不是与站点博客 相关联的 RSS 提要
有谁知道我在哪里可以找到这个页面的 json 提要? http://twitter.com/#!/microsoft 我找到的最接近的是这个: http://twitter.com/status/us
如何使用 nuget 命令禁用 SSL 证书检查? PS C:\Softwares> .\nuget.exe list Unable to load the service index forsour
我订阅了许多 RSS 提要,主要来自我自己的时区(英国:目前是 GMT+1,又名 BST)。不过我也对新西兰的新闻感兴趣(目前为 GMT+12)。 我的问题是由于我沉迷于需要将未读计数保持在或接近于零
关闭。这个问题需要更多focused .它目前不接受答案。 想改善这个问题吗?更新问题,使其仅关注一个问题 editing this post . 6年前关闭。 Improve this questi
我在 vb.net 设置中使用 fullCalendar。我使用包含在 aspx 页面中的 JSON 提要将数据传递到日历,如下所示: events: "JSONcalendarFeed.aspx"
我的应用程序使用雅虎的天气信息 (XML) 来显示 future 5 天的天气预报。当邮政编码在美国时,这很有效。例如,下面的 url 为我提供了密歇根州富兰克林的提要。 http://xml.wea
我有一个显示我的 Instagram 动态的网站。以前我在用Instagram 遵循 API。用户/ self /媒体/最近 此 API 使用我生成一次的访问 token ,并在我的代码中作为变量保存
是否可以为特定关键字获取 BlogSpot 的 RSS 提要? 我已尝试使用以下 URL,但它们似乎不起作用。 Atom 1.0: https://blogname.blogspot.com/
Basecamp 对其 RSS 提要使用 HTTP 身份验证,但这意味着 Google Reader, Bloglines and Firefox/Safari RSS don't work . 是否
是否可以创建多语言的 RSS (2.0) 提要?假设我主要用英语( en )写博客,但有时我会创建德语( de )帖子。 RSS 规范中是否对此提供支持?我在 RSS spec 中找不到任何内容在这个
我是一名优秀的程序员,十分优秀!