私はいくつかの追加のクレジット プロジェクトに取り組んでおり、プログラムの自動チェック サーバーを介して送信しようとすると、Symbol Not found エラーが発生し、コードの実行が停止します...その理由は完全にはわかりません。すべてが範囲内にあり、正しく綴られているようです。
何か案は?
public class Chap72 {
public static void main(String[] args) throws IOException {
//User inputs url and name of file to create.
WebReader instance = new WebReader();
Scanner console = new Scanner(System.in);
System.out.println("Enter a URL");
String url = console.nextLine();
System.out.println("Enter name of file");
Scanner location = new Scanner(System.in);
String fileName = location.next();
String filename = "PARSEDRESULT.txt";
try {
//uses both saveURL for the unaltered HTML
//uses SaveToURLPage for extracting links.
instance.SaveToURLPage(url, filename);
instance.saveURL(instance.Navigate(url), fileName);
}
catch (MalformedURLException e) {
//catches MalformedURLException
e.printStackTrace();
}
}
}
エラー:
error: cannot find symbol
instance.SaveToURLPage(url, filename);
^
symbol: method SaveToURLPage(String,String)
location: variable instance of type Chap72
1 error
なぜこのエラーが発生するのか完全にはわかりません...
WebReader
public class WebReader implements WebPage {
/**
*
* @param url to search through
* @return pageLocation
* @throws MalformedURLException
*/
public URL Navigate(String url) throws MalformedURLException {
//Creates a URL object
URL pageLocation = new URL(url);
return pageLocation;
}
/**
*
* @param location url hypertext link
* @param fileName name of text file to save to
* @throws IOException
*/
public void saveURL(URL location, String fileName) throws IOException {
Scanner in = new Scanner(location.openStream());
PrintWriter out = new PrintWriter(fileName);
//Scans the website
while (in.hasNextLine()) {
//prints out Information from URL
out.println(in.nextLine());
}
in.close();
out.close();
}
/**
*
* @param url to search through
* @param filename to save to
* @throws IOException
*/
public void SaveToURLPage(String url, String fileName) throws IOException {
// Creates a new URL object to retreive information.
URL pageLocation = new URL(url);
Scanner in = new Scanner(pageLocation.openStream());
PrintWriter out = new PrintWriter(fileName);
while (in.hasNext()) {
//Cycles through each character
String line = in.next();
if (line.contains("href=\"http://")) {
//if it has an <a> tag, the link is extracted
int from = line.indexOf("\"");
int to = line.lastIndexOf("\"");
out.println(line.substring(from + 1, to));
}
}
in.close(); //closes program
out.close();
}
}