首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >找不到<Class>类型的Symbol:变量>object>?

找不到<Class>类型的Symbol:变量>object>?
EN

Stack Overflow用户
提问于 2013-10-09 11:41:03
回答 1查看 2.5K关注 0票数 0

我正在做一些额外的学分项目,当我试图通过我的程序的自动检查服务器提交它时,它给了我一个Symbol Not found错误,并停止运行我的代码…我不完全确定为什么,因为一切似乎都在范围内,拼写正确。

有什么想法吗?

代码语言:javascript
复制
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();
        }
    }
}

错误:

代码语言:javascript
复制
error: cannot find symbol
instance.SaveToURLPage(url, filename);
        ^
symbol:   method SaveToURLPage(String,String)
location: variable instance of type Chap72
1 error

我不完全确定为什么我会得到这个错误...

代码语言:javascript
复制
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();
}

}

EN

回答 1

Stack Overflow用户

发布于 2013-10-09 11:43:48

此错误意味着没有接受两个String对象作为在WebReader类中声明的参数的方法SaveToURLPage。要获得进一步的帮助,您需要发布WebReader类的内容(或JavaDoc),以便我们查看。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19262679

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档