0

我有这些代码的错误消息:

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 个错误"**

有人知道为什么吗?

4

1 回答 1

1

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

StringWriter outWriter = new StringWriter();
于 2013-04-25T18:03:22.287 回答