小编典典

找不到符号,Java,类加载器

java

当前正在做一个typestate项目,我在导入List类时遇到问题。当我尝试编译该类时,它将在命令行中引发错误,提示找不到符号,并指向列表符号。我想知道您如何解决此问题。它似乎适用于String和Integer,但不适用于List。

该Java文件是通过翻译.scr文件的另一个程序自动创建的。在scr文件中,我使用以下行:

type <java> "java.lang.List" from "rt.jar" as List;

Java文件:

 package demos.Redis;
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.io.PrintWriter;
    import java.net.Socket;
    import java.net.ServerSocket;
    import java.net.UnknownHostException;

    public class ClientRole  {
        private BufferedReader socketServerIn = null;
        private PrintWriter socketServerOut = null;
    public ClientRole(){
        ServerSocket serverServer = null;
        try {
            serverServer = new ServerSocket(20000);
        }
        catch(IOException e) {
            System.out.println("Unable to listen on ports");
            System.exit(+1);
        }
        Socket socketServer = null;
        try {
            System.out.println("Accepting...");
            socketServer = serverServer.accept();
            System.out.println("Server accepted");
        }
        catch(IOException e) {
            System.out.println("Accept failed");
            System.exit(+1);
        }
        try {
            socketServerIn = new BufferedReader(new InputStreamReader(socketServer.getInputStream()));
            socketServerOut = new PrintWriter(socketServer.getOutputStream(), true);
        }
        catch(IOException e) {
            System.out.println("Read failed");
            System.exit(+1);
        }
    }
    public void send_WATCHListToServer(List payload) { HERE IS WHERE IT BREAKS!!
        this.socketServerOut.println(payload);
    }
    public Choice1 send_Choice1LabelToServer(String payload) {
        this.socketServerOut.println(payload);
        int intLabelChoice1 = Integer.parseInt(payload);
        switch(intLabelChoice1){
            case 1:
            return new Choice1(Choice1.GET);
            case 2:
            return new Choice1(Choice1.WATCH);
            case 3:
            default:
            return new Choice1(Choice1.MULTI);
        }
    }
    public void send_GETStringToServer(String payload) {
        this.socketServerOut.println(payload);
    }
    public String receive_GET_respStringFromServer() {
        String line = "";
        try {
            line = this.socketServerIn.readLine();
        }
        catch(IOException e) {
            System.out.println("Input/Outpur error.");
            System.exit(+1);
        }
        return line;
    }
    public void send_MULTIStringToServer(String payload) {
        this.socketServerOut.println(payload);
    }
    public Choice2 send_Choice2LabelToServer(String payload) {
        this.socketServerOut.println(payload);
        int intLabelChoice2 = Integer.parseInt(payload);
        switch(intLabelChoice2){
            case 1:
            return new Choice2(Choice2.SET);
            case 2:
            return new Choice2(Choice2.DISCARD);
            case 3:
            default:
            return new Choice2(Choice2.EXEC);
        }
    }
    public void send_SETStringToServer(String payload) {
        this.socketServerOut.println(payload);
    }
    public void send_DISCARDStringToServer(String payload) {
        this.socketServerOut.println(payload);
    }
    public void send_EXECStringToServer(String payload) {
        this.socketServerOut.println(payload);
    }
    public Choice3 receive_Choice3LabelFromServer() {
        String stringLabelChoice3 = "";
        try {
            stringLabelChoice3 = this.socketServerIn.readLine();
        }
        catch(IOException e) {
            System.out.println("Input/Outpur error, unable to get label");
            System.exit(+1);
        }
        int intLabelChoice3 = Integer.parseInt(stringLabelChoice3);
        switch(intLabelChoice3){
            case 1:
            return new Choice3(Choice3.EXEC_OK);
            case 2:
            default:
            return new Choice3(Choice3.EXEC_FAIL);
        }
    }
    public String receive_EXEC_okStringFromServer() {
        String line = "";
        try {
            line = this.socketServerIn.readLine();
        }
        catch(IOException e) {
            System.out.println("Input/Outpur error.");
            System.exit(+1);
        }
        return line;
    }
    public String receive_EXEC_failStringFromServer() {
        String line = "";
        try {
            line = this.socketServerIn.readLine();
        }
        catch(IOException e) {
            System.out.println("Input/Outpur error.");
            System.exit(+1);
        }
        return line;
    }
   }

命令行


阅读 292

收藏
2020-11-30

共1个答案

小编典典

您的Java文件缺少java.util.List的import语句,这就是为什么它无法编译的原因。

与String和Integer不同,List不在java.lang包中。您需要导入java.util.List,而不是java.lang.List。

如果我正确地理解了您的情况,则您的其他程序正在生成import语句,并尝试为java.lang.List添加一个导入,该导入实际上并不存在。有趣的是,您的代码中没有java.lang.List的import语句。我不知道这是否是您其他程序或功能中的错误!但是,如果将.scr文件中的行替换为type <java> "java.util.List" from "rt.jar" as List;

2020-11-30