0

Currently doing a typestate project and I am having problems with importing the List class. When I try to compile the class it throws an error in command line saying cannot find symbol and points to the List symbol. I was wondering how you fix this. It seems to work for String and Integer but not for List.

The java file is automatically create via another program that translates .scr files. In the scr file I use the following line :

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

Java file:

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

Command Line

3
  • 5
    java.util.List instead of java.lang.List perhaps? Commented Jun 25, 2015 at 15:48
  • ah, very clever. I'll give it a bash. Commented Jun 25, 2015 at 15:49
  • never worked, but thanks Commented Jun 25, 2015 at 15:59

2 Answers 2

1

Your Java file is missing an import statement for java.util.List, which is why it's failing to compile.

Unlike String and Integer, List is not in the java.lang package. You need to import java.util.List, not java.lang.List.

If I'm understanding your scenario correctly, your other program is generating the import statements and attempting to add an import for java.lang.List, which doesn't actually exist. Interestingly, there's no import statement in your code for java.lang.List. I don't know if that's a bug in your other program or a feature! But more than likely your problem will go away if you replace your line in the .scr file with type <java> "java.util.List" from "rt.jar" as List;

Sign up to request clarification or add additional context in comments.

2 Comments

I think this should work but it doesn't. I do think there is a bug (and there are hundreds) in the translator program.
This does fix the problem. When I added the import it just changed the error but the new error was just return List from the method so easily fixed. And just realised that whoever made the code does not need to use List at all. Thank you everyone.
0

You are using the interface List but you didn't import it, it says that It can not find symbol java.lang.List because it is trying to search this class in the default java.lang package, add the import java.util.List and you are not going to have problems

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.