gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 11:07:41 25 4
gpt4 key购买 nike

我在自学使用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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com