找不到符号 - 符号:方法lastIndexOf(java.lang.String)location:class java.util.Scanner

时间:2011-04-25 10:04:22

标签: java find compiler-errors symbols

我的代码尝试提取文件名以加载文件,从而读取包含文件名的另一个文件:

public static void main(String[] args) throws IOException
{
    Scanner scan;
    String transFilename;
    String filename;

    scan = new Scanner(System.in);
    System.out.print("Enter the name of your transaction file please (include .txt extension): ");
    transFilename = scan.nextLine();
    scan = new Scanner(new FileReader(transFilename));

    filename = readLine.next(2,readLine.lastIndexOf(""));    
    Scanner input = new Scanner( new FileReader(filename));   
}

生成错误:

blah.java:72: cannot find symbol
symbol  : method lastIndexOf(java.lang.String)
location: class java.util.Scanner
            filename = readLine.next(2,readLine.lastIndexOf(""));    
                                               ^
1 error

当我尝试使用应该在java中构建的“.length”方法时会产生同样的错误......

2 个答案:

答案 0 :(得分:0)

似乎readLine的类型为Scanner,您尝试调用lastIndexOf()但该方法不属于Scanner

答案 1 :(得分:0)

你的readLine是java.util.Scanner ...我想你认为它是java.lang.String。