基本调试,我不知道如何解决这些错误:与Java
- 类或接口的预期错误
- 包不存在
- 找不到符号
- 类型的非法启动
- 不能访问的java.lang
我怎样才能更好地理解其中我的代码中的问题正在发生?我如何调试这些问题?
这里是我的代码:
import java.io.*;
public class ResourcesTesterApp {
public static void main(String[] args) {
String s1 = readLineWithResources();
String s2 = readLineWithFinally();
}
public static String readLineWithResources() {
System.out.println("Starting readLineWithResources method.");
try (RandomAccessFile in = new RandomAccessFile("products.ran", "r")) {
return in.readLine();
}} catch (IOException e) {
System.out.println(e.toString());
}
}
public static String readLineWithFinally() {
System.out.println("Starting readLineWithFinally method.");
RandomAccessFile in = null;
String s = null;
try {
in = new RandomAccessFile("products.ran", "r");
s = in.readLine();
} catch (IOException e) {
System.out.println(e.toString());
} finally {
if (in != null) {
try {
in.close();
System.out.println("RandomAccessFile closed");
} catch (IOException e) {
System.out.println("RandomAccessFile " + e.getMessage());
}
}
}
return s;
}
你有的问题不是修复错误...它找到它们并缩小你的问题开始。如果调试器的输出对您没有帮助,我建议您逐个分开代码以缩小范围。如果您对重现该问题的代码有任何疑问,请尝试在此处发帖。否则,恐怕这个问题不适合StackOverflow。请参阅常见问题解答:http://stackoverflow.com/faq – Brad
哪些行会抛出这些错误?此外,尝试格式化您的代码,使其可读。左侧间距和排列方括号非常重要。 – David
嗨艾米丽。你在这个问题上得票低于你的原因是因为你没有表现出你试图自己解决问题的任何迹象。将来,您应该明确指出您的问题具体是什么,您尝试解决问题的方法以及您认为是错误的。通过这种方式,它看起来像你想要获得知识,而不是让某人为你修复你的程序。=)还有其他的论坛可以提供更多的*给予codez!*种类的请求。 – asteri