简体   繁体   English

抛出异常类Java

[英]Throwing exception class java

I am coding a circular singly linked list 我正在编写一个循环单链接列表

public class CircularSLList<T>
{

    protected class SLNode<T>
    {
        public T info = null;
        public SLNode<T> next = null;
    }

    public SLNode<T> tail = null;
    protected int size = 0;

I'm trying to throw a user defined exception class 我正在尝试引发用户定义的异常类

public class EmptyListException extends RuntimeException
{
    public EmptyListException()
    {
        super();
    }
}

But i keep on getting an "EmptyListException can not be resolved error" 但是我不断收到“ EmptyListException无法解决的错误”

Here is my code 这是我的代码

   public T removeFromHead() throws EmptyListException
    {
        if(tail == null)
        {
            throw new EmptyListException() ;
            return null ;
        }

        else
        {
            tail.next = tail.next.next ;
            tail.next.next = null ;
        }
        return null;
    }

All my files are in the same folder and all variable names have been spelled correctly so I cannot figure out why I'm getting this error 我所有的文件都在同一个文件夹中,并且所有变量名的拼写正确,因此我无法弄清楚为什么出现此错误

Thanks 谢谢

You have no defined package, so java won't know what to inherit from the current working directory. 您没有定义的包,因此java将不知道从当前工作目录继承什么。

Choices, specify package on the first line of each class, or manually import the required classes. 选择,在每个类的第一行上指定包,或手动导入所需的类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM