2012-09-26 3 views
0

스트림에서 객체 ChatMassage을 읽고이 객체에 포함 된 메시지를 인쇄하려고합니다. 메서드는 getMassage()입니다. 처음 메시지를 인쇄하지만 다음 번에는 항상 첫 번째 메시지를 인쇄합니다. 뭐가 잘못 되었 니?스트림에서 객체를 읽는 중

while(keepGoing){ 

    System.out.println("Client: " + ((ChatMassage) in.readObject()).getMassage() + "\n"); 

} 

ChatMassage 클래스 : 여기

코드의 예입니다

public void setMassage(String msg) { 
     this.msg = msg; 
    } 

것은 나도 몰라 :

public class ChatMassage implements Serializable { 

    String msg, recipientName = null; 
    String senderName = "None"; 

    public void setMassage(String msg) { 
     this.msg = msg; 
    } 

    public void setRecipientName(String recName) { 
     recipientName = recName; 
    } 

    public String getMassage() { 
     return msg; 
    } 

    public String getRecipientName() { 
     return recipientName; 
    } 

    public void setSenderName(String name) { 
     senderName = name; 
    } 

    public String getSenderName() { 
     return senderName; 
    } 


} 

답변

0

나는 문제는이 방법에있다 생각 문제가 될 수 있지만 매개 변수를 "new_msg"와 같은 것으로 변경해보십시오. 나는 "this.msg"와 "msg"를 혼동한다고 생각한다.

관련 문제