【发布时间】:2013-11-14 17:01:24
【问题描述】:
随着我们最近从 WSED 5.2 迁移到 RAD 7.5,我们的代码中出现了一个应用程序破坏错误。
RAD 7.5 如此标记它,所有在类头的声明中(公共类 FoStringWriter 扩展 StringWriter 实现 FoWriter {)
- Exception IOException in throws clause of Writer.append(CharSequence, int, int) is not compatable with StringWriter.append(CharSequence, int, int)
- Exception IOException in throws clause of Writer.append(char) is not compatable with StringWriter.append(char)
- Exception IOException in throws clause of Writer.append(CharSequence) is not compatable with StringWriter.append(CharSequence)
我在网上找到的每篇文献都指出这是 Eclipse 中的一个“错误”,但我的开发人员应该已经拥有最新版本的 Eclipse 软件。所以我不知道该怎么做这个错误。有没有我还没有更新到的来自 IBM 的修复程序?或者有没有可以纠正这个错误的代码修复?
public class FoStringWriter extends StringWriter implements FoWriter {
public void filteredWrite(String str) throws IOException {
FoStringWriter.filteredWrite(str,this);
}
public static void filteredWrite(String str, StringWriter writer) throws IOException {
if (str == null) str = "";
TagUtils tagUtils = TagUtils.getInstance();
str = tagUtils.filter(str);
HashMap dictionary = new HashMap();
dictionary.put("&#","&#");
str = GeneralUtils.translate(str,dictionary);
writer.write(str);
}
}
编者按:
这个运行的过程会为我们的应用程序创建 PDF 文档。在 WSED 5.5 中,它有效,有一些错误,但没有任何东西阻止 PDF 被写入。
【问题讨论】:
-
有什么理由让
FoStringWriter成为StringWriter的子类?使它成为FilterWriter的子类,它委托给任意Writer(可能是StringWriter)似乎更自然。作为副作用,它可能会解决您的编译问题。 -
@Holger 我已经按照你的建议尝试过这个,但它似乎给我带来了一个完全不同的问题。在应用程序 wpm 中的 servlet 操作的服务方法之一中创建的未捕获异常。异常创建: javax.servlet.ServletException: java.lang.NoSuchMethodError: ny/dol/wpm/pdf/FoStringWriter.
(Ljava/io/Writer;)V 请注意,我必须在其他类中更改对 FoStringWriter 的调用,因为没有没有参数的FilterWrite的构造函数,这就是之前调用FoStringwriter的方式。我还必须添加一个(作家)构造函数。 -
NoSuchMethodError表示并非所有类都已正确更新。顺便说一句,向新的FoStringWriter添加一个默认构造函数并不难,它创建一个StringWriter作为目标Writer并将其传递给超级构造函数。但更大的问题是错误表示尚未找到采用 writer 的构造函数,因此FoStringWriter类本身尚未更新。 -
@Holger 我在课堂上实现 FilterWriter 时遇到问题。在我的应用程序中调用 FoStringWriter 的所有实例都调用了非参数化构造函数,而 FilterWriter 不包含该构造函数。有什么建议可以给我吗?
标签: java writer stringwriter