繁体   English   中英

我在println中不断收到“错误:找不到符号”

[英]I keep getting “error:Cannot find symbol” in println

我知道这是重复的,但是其他人似乎都无法解决我的问题,而且我在Google上找不到任何有帮助的东西。

这是我的代码:

import java.util.Scanner;

class File_Scanner{    
    public static void read(){
        try {
            File credentials_file = new File("credentials.txt");
            Scanner file_reader = new Scanner(credentials_file);
            String[] users = new String[6];
            int index_counter = 0;

            while (file_reader.hasNextLine()) {
                users[index_counter] = file_reader.nextLine();
                index_counter++;
            }

            file_reader.close();
        }
        catch (Exception e) {
          System.out.println(e.getClass());
        }
        System.out.println(users[0]);
    }
}

我得到的错误是:

File_Scanner.java:19: error: cannot find symbol
        System.out.println(users[0]);
                           ^
  symbol:   variable users
  location: class File_Scanner
1 error

感谢您所有的帮助! 你们是最棒的!

users是在try块内定义的,因此它不是try块外的有效变量。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM