2013-10-09 80 views
0

我正在通過一些額外的功勞項目,當我嘗試通過自動檢查服務器爲我的程序提交它時,它給了我一個符號未找到錯誤並停止運行我的代碼......我並不完全確定爲什麼因爲一切都在範圍之內,拼寫正確。找不到符號:變量>對象>類型<Class>?

任何想法?

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(); 
} 

}

+1

該方法不存在? –

+1

錯誤顯示「Chap72類型的變量實例」是可疑的。這意味着你有一個名爲'instance'的變量,其類型是'Chap72';換句話說,它不是您向我們展示的類型爲「WebReader」的「實例」。你在別的地方還有另外一個'instance',你試着調用'SaveToURLPage'嗎? – ajb

+0

我不確定你的意思。我創建的唯一實例是WebReader類的一個稱爲實例的對象,因此我可以使用SaveToURLPage方法。 – Rimshot

回答

3

此錯誤意味着有沒有這樣的方法SaveToURLPage接受兩個String對象作爲中聲明的參數3210班。對於任何進一步的幫助,您需要發佈WebReader類的內容(或JavaDoc),供我們參閱。

+0

使用WebReader類更新了OP。 – Rimshot

相關問題