。
我一直在研究一个双端 que(双端 que)类。我仍然有很多工作要做,但希望能够随时测试我的代码。我在线程"main"java.lang.NoSuchMethodError:main中收到异常。我将不胜感激任何解决此问题的帮助。
提前感谢,这是我的代码:
class DNode<E>
{
private E data;
private DNode<E> lLink, rLink;
public DNode(E iData, DNode<E> lefLink, DNode<E> riteLink)
{
data = iData;
rLink = riteLink;
lLink = lefLink;
}
public E getData()
{return data;}
public void setData(E aData)
{data = aData;}
public DNode<E> getRightLink()
{return rLink;}
public void setRightLink(DNode<E> righty)
{rLink = righty;}
public DNode<E> getLeftLink()
{return lLink;}
public void setLeftLink(DNode<E> lefty)
{lLink = lefty;}
public void addNodeAfter(E item)
{rLink = new DNode<E>(item, this, rLink);}
public void removeNodeAfter()
{rLink = rLink.getRightLink();}
}
class Deque<E>
{
private int manyNodes = 0;
private DNode<E> front, rear;
public Deque()
{
manyNodes = 0;
front = null;
rear = null;
}
public boolean isEmpty()
{return (manyNodes == 0);}
public void addAtEnd(E item)
{
if(isEmpty())
{
front.addNodeAfter(item);
rear = front;
}
else
{
rear.addNodeAfter(item);
rear = rear.getRightLink();
}
manyNodes++;
}
public void addtAtFront(E item)
{
if(isEmpty())
{
front.addNodeAfter(item);
rear = front;
}
else
{
front.addNodeAfter(item);
}
}
public void removeFirst() throws NoSuchFieldException
{
if(manyNodes == 0)
throw new NoSuchFieldException();
front.removeNodeAfter();
}
public void removeLast() throws NoSuchFieldException
{
if(manyNodes == 0)
throw new NoSuchFieldException("Ya dun goofed");
rear.removeNodeAfter();
}
public void print()
{
DNode<E> trace;
for(trace = front; trace.getRightLink() != null; trace = trace.getRightLink())
System.out.println(trace.getData());
}
}
class DequeRun
{
public static void main(String[] args)
{
Deque<String> test1 = new Deque<String>();
test1.addAtEnd("Ryan");
test1.addAtEnd("Mike");
test1.print();
}
}
让你的DequeRun成为公共的,否则jvm将无法在其中找到main方法