我正在尝试用java测试一些东西,但我有以下错误:
第16行:令牌“;”上的语法错误,{此标记后的预期
在第36行:语法错误,插入“}”以完成ClassBody
我已经在第36行插入了一个括号,但原则上没有必要......第16行的错误仍然存在
有人可以帮我发现问题是什么?
非常感谢你。
以下是我正在使用的类NewsCrawler.java的代码:
package upf.dad.proyecto;
import java.net.URL;
import java.util.Iterator;
import org.jsoup.Jsoup;
import com.sun.syndication.feed.synd.SyndEntry;
import com.sun.syndication.feed.synd.SyndFeed;
import com.sun.syndication.io.SyndFeedInput;
import com.sun.syndication.io.XmlReader;
public class NewsCrawler {
URL url = new URL("https://news.google.com/news/section?topic=t&ned=es&output=rss");
XmlReader reader = null;
try {
reader = new XmlReader(url);
SyndFeed feed = new SyndFeedInput().build(reader);
for (Iterator i = feed.getEntries().iterator(); i.hasNext();) {
SyndEntry entry = (SyndEntry) i.next();
System.out.println("Title: " + entry.getTitle());
System.out.println(" Description: " + Jsoup.parse(entry.getDescription().getValue()).text());
System.out.println(" Date: " + entry.getPublishedDate());
System.out.println(" Link: " + entry.getLink());
}
} finally {
if (reader != null) {
reader.close();
}
}
}
答案 0 :(得分:1)
缺少构造函数?
import java.net.URL;
import java.util.Iterator;
import org.jsoup.Jsoup;
import com.sun.syndication.feed.synd.SyndEntry;
import com.sun.syndication.feed.synd.SyndFeed;
import com.sun.syndication.io.SyndFeedInput;
import com.sun.syndication.io.XmlReader;
public class NewsCrawler
{
public NewsCrawler()
{
URL url = new URL("https://news.google.com/news/section?topic=t&ned=es&output=rss");
XmlReader reader = null;
try
{
reader = new XmlReader(url);
SyndFeed feed = new SyndFeedInput().build(reader);
for (Iterator i = feed.getEntries().iterator(); i.hasNext();)
{
SyndEntry entry = (SyndEntry) i.next();
System.out.println("Title: " + entry.getTitle());
System.out.println(" Description: " + Jsoup.parse(entry.getDescription().getValue()).text());
System.out.println(" Date: " + entry.getPublishedDate());
System.out.println(" Link: " + entry.getLink());
}
}
finally
{
if (reader != null)
{
reader.close();
}
}
}
}