错误:找不到符号(dataOutputStream out)[重复]
Posted
技术标签:
【中文标题】错误:找不到符号(dataOutputStream out)[重复]【英文标题】:error : cannot find symbol (dataOutputStream out) [duplicate] 【发布时间】:2021-11-21 16:15:38 【问题描述】:我是 Java 新手,对网络编程不是很精通。我有这个我无法解决的错误。下面的代码是选择性重复过程的客户端,它说它找不到符号。
import java.util.*;
import java.net.*;
import java.io.*;
public class SelectRepeatClient
public static void main(String[] args) throws Exception
try
Socket s = new Socket("localhost", 6060);
DataInputStream din = new DataInputStream(s.getInputStream());
DataOutputStream dout = new DataOutputStream(s.getOutputStream());
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the no of input : ");
int n = Integer.parseInt(br.readLine());
ArrayList<String> name = new ArrayList<String>();
ArrayList<Double> phone = new ArrayList<Double>();
ArrayList<String> email = new ArrayList<String>();
for (int i = 0; i < n; i++)
System.out.println("Enter name : ");
String nn = br.readLine();
System.out.println("Enter phone : ");
double ph = Double.parseDouble(br.readLine());
System.out.println("Enter email : ");
String e = br.readLine();
name.add(nn);
phone.add(ph);
email.add(e);
dout.writeInt(n);
for (int i = 0; i < n; i++)
String nname = name.get(i);
String eemail = email.get(i);
double pphone = phone.get(i);
dout.writeUTf(nname);
dout.writeDouble(pphone);
dout.writeUTf(eemail);
dout.flush();
System.out.println("Data sent...");
int size = din.readInt();
if (size != 0)
ArrayList<pair> err = new ArrayList<pair>();
for (int i = 0; i < size; i++)
int val1 = din.readInt();
int val2 = din.readInt();
err.add(new pair(val1, val2));
System.out.println("resending data...");
for (int i = 0; i < size; i++)
switch (err.get(i).getval2())
case 1:
String nname=name.get(err.get(i).getval1());
dout.writeUTf(nname);
dout.flush();
break;
case 2:
double pphone = phone.get(err.get(i).getval1());
dout.writeDouble(pphone);
dout.flush();
break;
case 3:
String eemail = email.get(err.get(i).getval1());
dout.writeUTf(eemail);
dout.flush();
System.out.println("data sent... ");
dout.close();
din.close();
s.close();
catch (Exception e)
System.out.println(e);
class pair
int val1, val2;
pair(int v1, int v2)
this.val1 = v1;
this.val2 = v2;
void setval1(int ans)
this.val1 = ans;
void setval2(int ans)
this.val2 = ans;
int getval1()
return val1;
int getval2()
return val2;
这是我得到的错误:
SelectRepeatClient.java:33: error: cannot find symbol
dout.writeUTf(nname);
^
symbol: method writeUTf(String)
location: variable dout of type DataOutputStream
SelectRepeatClient.java:35: error: cannot find symbol
dout.writeUTf(eemail);
^
symbol: method writeUTf(String)
location: variable dout of type DataOutputStream
SelectRepeatClient.java:52: error: cannot find symbol
dout.writeUTf(nname);
^
symbol: method writeUTf(String)
location: variable dout of type DataOutputStream
SelectRepeatClient.java:62: error: cannot find symbol
dout.writeUTf(eemail);
^
symbol: method writeUTf(String)
location: variable dout of type DataOutputStream
4 errors
【问题讨论】:
【参考方案1】:Java 是一种区分大小写的语言。 DataOutputStream
类中没有writeUTf()
(小写f
)方法,正确的名称是writeUTF()
(大写F
)。
【讨论】:
哦,好吧,但是我在 vscode 中使用了 tabnine,它说 writeUTf() 即使我试图将它更改为 writeUTF() 它也会自动更正,非常感谢它现在编译 那么tabnine错了。以上是关于错误:找不到符号(dataOutputStream out)[重复]的主要内容,如果未能解决你的问题,请参考以下文章