所以我正在为rss程序编写一些代码,但是我的代码找不到问题。我有4个问题,当我观看视频时,它看上去完全一样。请帮我。先感谢您。这是错误,
Main.java:27: error: illegal start of type
} catch (MalformedURLException ue) {
^
Main.java:29: error: illegal start of type
} catch (IOException ioe) {
^
Main.java:32: error: illegal start of type
return null;
^
Main.java:32: error: ';' expected
return null;
^
Main.java:35: error: class, interface, or enum expected
}
^
5 errors
我研究了几个不同线程上的堆栈溢出,但是没有任何信息有用。我删除了花括号,添加了花括号,添加了分号,没有任何效果
import java.io.*;
import java.net.*;
public class RSSReader {
public static void Main(String[] args) {
System.out.printIn(ReadRSS("https://www.oracle.com/technetwork/topics/newtojava/overview/index.html/pageslug?format=rss"));
}
public static String readRSS(String urlAddress) {
URL rssUrl = new URL(urlAddress);
BufferedReader in = new BufferedReader(new InputStreamReader(rssUrl.openStream()));
String sourceCode = "";
String line;
while((line = in.readLine())!=null) {
if (line.contains("<title>")) {
int firstPos = line.indexOf("<title>");
String temp = line.substring(firstPos);
temp = temp.replace("<title>", "");
int lastPos = temp.indexOf("</title>");
temp = temp.substring(0, lastPos);
sourceCode += temp+"\n";
}
}
in.close();
return sourceCode;
} catch (MalformedURLException ue) {
System.out.printIn("Malformed URL");
} catch (IOException ioe) {
System.out.printIn("Something went wrong reading the contents");
}
return null;
}
}
答案 0 :(得分:3)
通常,此错误表示您在闭合括号}
上放错了位置。在这种情况下,您将缺少try {
和catch
一起使用的 public static class ServiceCollectionExt
{
public static void AddSingleton<I1, I2, T>(this IServiceCollection services)
where T : class, I1, I2
where I1 : class
where I2 : class
{
services.AddSingleton<I1, T>();
services.AddSingleton<I2, T>(x => (T) x.GetService<I1>());
}
}
(注意开头括号)。
答案 1 :(得分:2)
缺少尝试{
和System.out.printIn
错误,应该是System.out.println
import java.io.*;
import java.net.*;
public class RSSReader {
public static void Main(String[] args) {
System.out.printIn(
ReadRSS("https://www.oracle.com/technetwork/topics/newtojava/overview/index.html/pageslug?format=rss"));
}
public static String readRSS(String urlAddress) {
try {
URL rssUrl = new URL(urlAddress);
BufferedReader in = new BufferedReader(new InputStreamReader(rssUrl.openStream()));
String sourceCode = "";
String line;
while ((line = in.readLine()) != null) {
if (line.contains("<title>")) {
int firstPos = line.indexOf("<title>");
String temp = line.substring(firstPos);
temp = temp.replace("<title>", "");
int lastPos = temp.indexOf("</title>");
temp = temp.substring(0, lastPos);
sourceCode += temp + "\n";
}
}
in.close();
return sourceCode;
} catch (MalformedURLException ue) {
System.out.println("Malformed URL");
} catch (IOException ioe) {
System.out.println("Something went wrong reading the contents");
}
return null;
}
}