2013-11-14 99 views
4

從我們最近從WSED 5.2轉向RAD 7.5的過程中,我們的代碼中出現了應用程序破壞的問題。StaticWriter和Writer類之間的衝突

RAD7.5馬克它正是如此,所有的類頭的聲明(public類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);  
} 

}

Editory注:

,這種運行產生的PDF文檔爲我們的應用程序的過程。在WSED 5.5中,它工作,出現了一些錯誤,但沒有任何東西阻止了PDF的寫入。

+1

是否有任何理由讓'FoStringWriter'成爲'StringWriter'的一個子類?使它成爲FilterWriter的子類,它委託給一個任意的Writer(它可能是一個StringWriter)似乎更自然。它可能會解決您的編譯問題,作爲一個副作用。 – Holger

+0

@Holger我按照你的建議試過這個,但它似乎爲我創造了一個完全不同的問題。在應用程序wpm中的servlet操作的服務方法之一中創建的未捕獲異常。創建的異常:javax.servlet.ServletException:java.lang.NoSuchMethodError:ny/dol/wpm/pdf/FoStringWriter。請注意,我不得不在其他類中調用FoStringWriter,因爲沒有構造函數的FilterWrite沒有參數,這是FoStringwriter之前被調用的方式。我還必須添加一個(作家)構造函數。 – Zibbobz

+1

'NoSuchMethodError'指示並非所有類都已正確更新。順便說一句,添加一個默認的構造函數到新的'FoStringWriter'中並不難,因爲這個''FoStringWriter'創建一個'StringWriter'作爲目標'Writer'並將其傳遞給超級構造函數。但是更大的問題是錯誤表明沒有找到編寫器的構造函數,所以它是沒有更新的'FoStringWriter'類本身。 – Holger

回答

1

拍拍我的額頭,因爲這是另一個「錯誤」,由一個看似完全明顯的答案解決。

只需添加列出的方法,拋出「錯誤」,我可以消除調用這個類時拋出的錯誤。

直接從StringWriter複製它們實際上是工作的,沒有以任何方式編輯它們。

public StringWriter append(char c) { 
    write(c); 
    return this; 
} 

public StringWriter append(CharSequence csq) { 
    if (csq == null) 
     write("null"); 
    else 
     write(csq.toString()); 
     return this; 
} 

public StringWriter append(CharSequence csq, int start, int end) { 
    CharSequence cs = (csq == null ? "null" : csq); 
    write(cs.subSequence(start, end).toString()); 
     return this; 
} 

我都高興的是這個工作,並在同一時間感到沮喪,這是如此離譜的簡單修復,它幾乎花了整整一個星期要弄清楚。

我想這個錯誤背後的原因可能是實施中的衝突。 FoStringWriter擴展了StringWriter,但它自己擴展了Writer,並且這兩個類都有自己的「附加」方法,可以相互覆蓋。通過顯式創建它們,解決了這個錯誤。