2012-04-29 45 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

相关问题