2012-04-29 41 views
-2
ManageStock2.java:104: error: method writeUTF in class RandomAccessFile cannot b 
e applied to given types; 
             in.writeUTF(authors , titles ,ISBN); 
             ^
    required: String 
    found: String,String,String 
    reason: actual and formal argument lists differ in length 
1 error 

我已經初始化了變量。爲什麼我傳遞RandomAccessFile.writeUTF這些參數時會出錯?

String ISBN,ISBN2,authors,titles; 
int levels,level2,stock; 

我需要知道該寫什麼。我已經檢查過API了。

+3

沒有你明白的部分錯誤消息的? – meriton 2012-04-29 12:26:16

+0

你是否100%確定你應該在這裏使用英國皇家空軍? – 2012-04-29 12:27:43

+0

是的100%肯定(氣墊船)。 我不知道爲什麼它接受in.writeUTF(作者等)(meriton) – 2012-04-29 12:29:31

回答

2

功能takes one argument,你提供三個。將呼叫拆分爲三部分:

in.writeUTF(authors); 
in.writeUTF(titles); 
in.writeUTF(ISBN); 

這將一個接一個地寫入三個字符串。如果您想要應用格式(例如字段分隔符等),則可以使用StringBuilderString.format()

+0

繼承人我的代碼http://pastebin.com/63ahnfjh – 2012-04-29 12:37:49

+0

@ AndrewO'Neill在代碼你需要多次呼叫。 – 2012-04-29 13:26:02

1

像錯誤消息說,你參數調用writeUTF,但它需要only one

公衆最終無效writeChars(String s) 拋出IOException異常

一個字符串寫入到文件一系列字符。每個字符都寫入數據輸出流,就像通過writeChar方法一樣。寫入從文件指針的當前位置開始。

相反,使三個獨立的電話:

in.writeUTF(authors); 
in.writeUTF(titles); 
in.writeUTF(ISBN); 
+0

http://pastebin.com/63ahnfjh繼承人我的代碼 – 2012-04-29 12:38:25

相關問題