我一直在研究deque(双端que)课程。我仍然需要对所有方法做很多工作,但希望能够像我一样测试我的代码。我在线程“main”java.lang.NoSuchMethodError:main中得到一个Exception。我很感激任何帮助解决这个问题。
先谢谢,这是我的代码:
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();
}
}
答案 0 :(得分:3)
让你的DequeRun公开,否则jvm将无法在其中找到主要方法