java - 错误: cannot find symbol java for inner class

标签 java sockets compiler-errors

我在自学使用java进行套接字编程,并且在编译时遇到此问题。我在主类Book内声明了一个内部类library_s,并且编译器无法识别在Status类中定义的变量Book。我将Book用作static class,因为我读到枚举仅存在于静态类中。我想要一个C语言中的"struct"的类似物,因为我对此很熟悉。我看过其他各种类似的错误,但是它们都没有帮助。请帮忙。谢谢!

public class library_s extends Thread{

private ServerSocket lib_server;

LinkedList<Book> library = new LinkedList<Book>();

//constructor

  public library_s(int port) throws IOException{
    lib_server = new ServerSocket(port);
    lib_server.setSoTimeout(10000);
    }

public void run(){

Socket server = lib_server.accept();
    System.out.println("Connected to " + server.getRemoteSocketAddress());

    DataInputStream is = new DataInputStream(server.getInputStream());

    DataOutputStream os = new DataOutputStream(server.getOutputStream());

    for(library b : library){
      if(b.BookName == is.readUTF(){
           if(b.Status == FORISSUE){
         //enter rest of the body here
       }
      }

     }

   public static class Book{
    public String BookName;
    public static enum Status {FORISSUE, ISSUED, RENEW, RESERVE};

    public Book(String bn){
            this.BookName = bn;
            this.Status =   FORISSUE;
    }
}

public static void main(String [] args){
int port = Integer.parseInt(args[0]);
try{
    Thread t = new library_s(port);
    t.start();
} catch (IOException e){
    e.printStackTrace();
   }
  }
 }
}

编译器给出错误
library_s.java:64: error: cannot find symbol
    if(b.Status == FORISSUE){           
        ^
symbol:   variable Status
location: variable b of type Book
library_s.java:64: error: cannot find symbol
    if(b.Status == FORISSUE){           
                   ^

最佳答案

您在类enum中声明了Book,因此无法从外部(其他类)识别它。
为了对其进行修复,可以使用与程序包中其他任何类相同的方式声明library_s内或Book外的枚举,或者,如果要将该枚举保留在Book类内,则可以使用以下命令进行访问:

Book.Status.FORISSUE

关于java - 错误: cannot find symbol java for inner class,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25368907/

相关文章:

java - 如何通过 Java Web 服务器在浏览器中显示图像/gif

java - 列表中的值未由线程更新

java - 使用类名称从字符串动态调用类变量

node.js npm install ws 错误 "npm ERR! network"安装 Web 套接字

sockets - 可以创建多少个 tcp 连接

javascript - Testcafe Applitools typescript - 错误 : Property 'accessibilityValidation' is missing in type

c# - 如何防止隐藏或覆盖公共(public)属性(property)

java - 编译时找不到符号方法?

java - 使用 GitHub 通过 Jenkins 将 EAR 部署到 WAS8.5 时出现 IncompatibleClassChangeError

java - 查找 Map 中的最高 n 个值