2017-10-05 45 views
0

enter image description herecom.sun.jdi.InvocationException調用方法,同時調試

我想實現循環鏈​​表和獲取異常調試時「發生com.sun.jdi.InvocationException調用方法。」

任何人都可以讓我知道爲什麼我得到這個例外。

public int data; 
    public Node head; 

    public CLinkedList() { 
     super(); 
    } 

    public void append(int data){ 
     Node n = new Node(data); 
     if(isEmpty()){ 
      head = n; 
      n.setNext(head); // Here is the exception, but i am not getting why it is coming. 
     } 
     else{ 
      Node temp = head; 
      while(temp.getNext() != head){ 
       temp = temp.getNext(); 
      } 
      temp.setNext(n); 
      n.setNext(head); 
     } 
    } 

    public boolean isEmpty(){ 
     if(null == head){ 
      return true; 
     } 
     return false; 
    } 

enter image description here

+0

代碼沒有問題,我運行它,它工作正常。也許添加Node實現。並添加您正在使用的資源,如com.sun.jdi庫 – Adi

+0

請參閱上面更新的圖像,謝謝 – user3676578

+0

當我實現它的工作,所以你的發佈的代碼不是問題,但我實現了我自己的節點類,所以請包括你的Node庫路徑,也可以嘗試自己實現它。 – Adi

回答

0

我發現了問題。

這段代碼在執行時工作正常,但在調試時,由於Node類中的重寫的toString()方法,它給了我一個異常。

@Override 
    public String toString() { 
     return "Node [data=" + data + ", next=" + next + "]"; 
    } 

在調試模式下

當我們將在參考mouseHover,內部它將調用我們已重寫並會嘗試打印toString()方法,在這種情況下,它在本質上是圓形的,所以它拋出「InvocationException」。