[英]Error in Java: incompatible types: LinkedList<Diff> cannot be converted to String
Hello I need help with this error, thank you in advance for your time and consideration您好,我需要有关此错误的帮助,提前感谢您的时间和考虑
In the this.txt_absent.setText(diff);在this.txt_absent.setText(diff); line is where the error appears, I want to show the diff in a JTextArea
行是出现错误的地方,我想在JTextArea
中显示差异
This is my code: (It is an ActionPerformed JButton
)这是我的代码:(这是一个 ActionPerformed JButton
)
private void compareActionPerformed(java.awt.event.ActionEvent evt) {
diff_match_patch dmp = new diff_match_patch();
LinkedList <diff_match_patch.Diff> diff = dmp.diff_main(txt_guide.getText() , txt_result.getText());
dmp.diff_cleanupSemantic(diff);
this.txt_absent.setText(diff);
}
JTextArea
does not accept LinkedList
instance in setText
method. JTextArea
不接受setText
方法中的LinkedList
实例。
You need to convert the linked list to appropriate string in any convenient way.您需要以任何方便的方式将链表转换为适当的字符串。
The simplest way can be to call LinkedList::toString
:最简单的方法是调用LinkedList::toString
:
this.txt_absent.setText(diff.toString());
Or it is possible to join the elements in the linked list with "\n"
delimiter providing that LinkedList
implements Iterable
:或者可以使用"\n"
分隔符连接链表中的元素,前提是LinkedList
实现了Iterable
:
this.txt_absent.setText(String.join("\n", diff));
Or implement a custom method to build a string from the linked list.或者实现自定义方法以从链表构建字符串。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.