简体   繁体   English

Java错误:类型不兼容:LinkedList<diff> 不能转换成字符串</diff>

[英]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.

相关问题 JAVA - 错误不兼容类型:字符串无法转换为字符串 [] - JAVA - Error incompatible types: String cannot be converted to String[ ] 错误:不兼容的类型:java.lang.String 无法转换为 String - error: incompatible types: java.lang.String cannot be converted to String Java错误,类型不兼容:无法将对象转换为字符串 - Java Error, Incompatible types: Object cannot be converted to string 错误:不兼容的类型:String[] 无法转换为 String - error: incompatible types: String[] cannot be converted to String BlueJ错误:“不兼容的类型:int无法转换为java.lang.String”和“不兼容的类型:java.lang.String无法转换为int” - BlueJ Error: “Incompatible types: int cannot be converted java.lang.String” AND “Incompatible types: java.lang.String cannot be converted to int” Java : 不兼容的类型; int 不能转换为字符串 - Java : incompatible types; int cannot be converted to string Java JComboBox不兼容类型:无法转换为字符串 - Java JComboBox Incompatible Types: Cannot be converted to string 错误:类型不兼容:字符串无法转换为URI - error: incompatible types: String cannot be converted to URI 错误:不兼容的类型:int 无法转换为 String - error: incompatible types: int cannot be converted to String 错误:类型不兼容:char无法转换为String - error: incompatible types: char cannot be converted to String
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM