I have this code, but it gives error at here: throw new MessageTooLongException();, it says "No enclosing instance of type MessageLenght is accessible. Must qualify the allocation with an enclosing instance of type MessageLenght (e.g. x.new A() where x is an instance of MessageLenght)." I am using Eclipse. I cannot figure it out why it gives error. Please help me.
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.*;
class MessageLenght extends MessageTooLongException
{
    public static void main(String[] args)
    {
        Scanner keyboard = new Scanner(System.in);
        try
        {
            char ch;
            do
            {   
                System.out.println("Please enter the text: ");;
                String hr = keyboard.nextLine();
                int count = hr.length();
                if(count>= 20)
                {
                    throw new MessageTooLongException();
                }
                else
                {
                    System.out.println("Text: " + count + "characrters which is acceptable length.");
                }
                System.out.println("Do you want to continue- Y/N");
                BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
                String s = br.readLine();
                ch = s.charAt(0);
            }
            while((ch =='Y') || (ch =='y'));
        }
        catch(MessageTooLongException ex)
        {
            System.out.println(ex.getMessage());
        }
        catch(IOException ex)
        {
            System.out.println(ex.getMessage());
        }
    }
    class MessageTooLongException extends Exception
    {
        public MessageTooLongException()
        {
            super("Message Too Long Exception");
        }
        public MessageTooLongException(String msg)
        {
            super(msg);
        }
    }
}
 
     
    