在java netbeans中找不到符号方法 [英] Cannot find symbol method append in java netbeans

查看:288
本文介绍了在java netbeans中找不到符号方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在java netbeans中找不到符号方法

可能是什么问题



Cannot find symbol method append in java netbeans
what could be the problem

try {
    String msg = dis.readUTF();
    txt_recMsg.append("\n"+msg);
} catch (IOException ex) {
    Logger.getLogger(ClientForm.class.getName()).log(Level.SEVERE, null, ex);
}

推荐答案

可能这是由字符串中的反斜杠引起的。您可以解决如下(双反斜杠):

Probably this caused by backslash in your string. You can solve as follows (double backslash):
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);
}





我已经通过添加StringBuilder更新了代码。它具有更好的性能,您可以调用附加到StringBuilder。可以使用setText方法更新textField。



您可以从这里 [ ^ ]!



让我知道它是否有效!



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!

您尚未在上面的代码中声明变量 txt_recMsg 。但假设它是字符串,则没有追加方法,因为文档 [ ^ ]显示。您需要使用 StringBuffer类 [ ^ ]。
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[^].


这篇关于在java netbeans中找不到符号方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆