javaswingioexceptionjava-17lanterna

IOExecption at createTerminal() in Java Lanterna


So I came across Lanterna and I decided to use it for my terminal based text editor project but when you try to run the basic create terminal boilerplate code on Windows, you'll get an IOException error.

This is the code:

public class Main {
    public static void main(String[] args) {
            Terminal terminal = new DefaultTerminalFactory().createTerminal();
    }
}

and this is the error:

java: unreported exception java.io.IOException; must be caught or declared to be thrown

Solution

  • The solution to this is simple, just import IOException and enclose the terminal boilerplate code in a try catch expression.

    
    import java.io.IOException;
    public class Main {
        public static void main(String[] args)  {
            try{
                Terminal terminal = new DefaultTerminalFactory().createTerminal();
    
            }
            catch(IOException e){
                e.printStackTrace();
            }
        }
    }
    

    Now the code will run without any errors