gpt4 book ai didi

java - 为什么 getBuffer() 会出现错误?

转载 作者:行者123 更新时间:2023-12-01 14:38:39 24 4
gpt4 key购买 nike

为什么我收到这些代码的错误消息:

TransformerFactory tf = TransformerFactory.newInstance();
Transformer t = tf.newTransformer();
DOMSource source = new DOMSource(doc);
Writer outWriter = new StringWriter();
StreamResult result = new StreamResult( outWriter );
t.transform(source, result);
StringBuffer sb = outWriter .getBuffer(); //with this line,complet error message down
return sb.toString();

} catch (Exception e) {
System.out.println(e.getMessage());
}
return null;

}

**down: "StringBuffer sb = outWriter .getBuffer();
symbol: method getBuffer()
location: variable outWriter of type Writer

注意:C:\Users\Desktop\BikeShop FINALE\src\bikeshop\orej.java 使用未经检查或不安全的操作。 注意:使用 -Xlint:unchecked 重新编译以了解详细信息。 1 个错误“**

有人知道为什么吗?

最佳答案

getBuffer 方法未为 java.io.Writer 定义。声明为 StringWriter:

StringWriter outWriter = new StringWriter();

关于java - 为什么 getBuffer() 会出现错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16221585/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com