基本調試,我不知道如何解決這些錯誤:與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