Click here to Skip to main content
15,896,153 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Cannot find symbol method append in java netbeans
what could be the problem

Java
try {
    String msg = dis.readUTF();
    txt_recMsg.append("\n"+msg);
} catch (IOException ex) {
    Logger.getLogger(ClientForm.class.getName()).log(Level.SEVERE, null, ex);
}
Posted
Updated 13-Feb-20 5:11am
v2

Probably this caused by backslash in your string. You can solve as follows (double backslash):
Java
try {
String msg = dis.readUTF();
String oldText = txt_recMsg.getText();

StringBuilder yourStringBuilder = new StringBuilder();
yourStringBuilder.append(oldText);
yourStringBuilder.append("\\n");
yourStringBuilder.append(msg);

txt_recMsg.setText(yourStringBuilder.toString());
} catch (IOException ex) {
Logger.getLogger(ClientForm.class.getName()).log(Level.SEVERE, null, ex);
}


I've updated the code with adding StringBuilder. It has better performance and you can invoke append to StringBuilder. After your textField could be updated with setText method.

You can read more String vs. StringBuilder performace from here[^]!

Let me know if it works or not!
 
Share this answer
 
v5
Comments
kami124 11-Jun-14 6:25am    
Still same problem, problem some where in txt_recMsg
norbitrial 11-Jun-14 6:30am    
Is txt_recMsg a textfield or textbox? Have you declared txt_recMsg before you wanted to invoke append method?
kami124 11-Jun-14 6:34am    
its textfield. first i create txt_recMsg and then invoke append method
norbitrial 11-Jun-14 6:56am    
I've improved my solution with StringBuilder for better performance and setText method in order to change the value of your textField.
kami124 11-Jun-14 7:15am    
Perfect its working
You have not declared the variable txt_recMsg in the above code. But assuming it is a string, then there is no append method, as the documentation[^] shows. You need to use the StringBuffer class[^].
 
Share this answer
 
Comments
kami124 11-Jun-14 6:36am    
its declared its textfield

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900