开发者

cannot find symbol -- symbol : method lastIndexOf(java.lang.String) location: class java.util.Scanner

My code tries to extract a filename to load a file from reading another file that contains the filename:

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

the Error generated:

blah.java:72: cannot find symbol
symbol  : method lastIndexOf(java.lang.String)
location: class java.util.Scanner
            filename = readLine.ne开发者_JAVA百科xt(2,readLine.lastIndexOf(""));    
                                               ^
1 error

The same error is generated when i tried to use ".length" method that should be built into java...


It seems readLine is of type Scanner and you are trying to invoke lastIndexOf() but thi method doesn't belong to Scanner class


Your readLine is java.util.Scanner... I guess you're thinking that it's a java.lang.String.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜