當我在調試期間嘗試直觀顯示對象的toString()
值時,我收到此消息。 我toString
方法是這樣的:com.sun.jdi.InvocationException在其內部使用switch-case時發生了調用方法toString
@Override
public String toString(){
String s = "ACTION: <P"+this.playerSit+" "+this.type;
switch(this.type){
case DISCARD:
s+=" "+this.cardDiscarded+">";
break;
case CALLVALUE:
s += " "+this.valueCalled+">";
break;
case CALLSCORE:
s += " "+this.scoreToWin+">";
break;
case CALLSUIT:
s += " "+this.suitCalled+">";
break;
}
return s;
}
添加的switch-case構建它工作得很好了。
編輯:我修改了代碼如下:
@Override
public String toString(){
String s = "";
s += "ACTION: <P"+this.playerSit+" "+this.type;
if(this.type == Type.DISCARD)
s += " "+this.cardDiscarded+">";
if(this.type == Type.CALLVALUE)
s += " "+this.valueCalled+">";
if(this.type == Type.CALLSCORE)
s += " "+this.scoreToWin+">";
if(this.type == Type.CALLSUIT)
s += " "+this.suitCalled+">";
return s;
}
,現在,它再次工作。所以問題在於開關櫃,但我不知道爲什麼。
什麼是錯誤?什麼是這種類型的數據類型? – Keerthivasan
不相關 - 但相關:不要使用'+ ='創建字符串:改爲使用'StringBuilder'。 http://docs.oracle.com/javase/tutorial/java/data/buffers.html – Darkhogg