Java找不到符号
我正在 Applet 模式下创建 TCP 客户端,但出现了这个奇怪的错误...
C:\Users\Dan\Documents\DanJavaGen\ClientApplet.java:20: cannot find symbol
symbol : method printStrackTrace()
location: class java.lang.Exception
e.printStrackTrace();
^
1 error
Tool completed with exit code 1
代码:
import java.io.*;
import java.applet.Applet;
import java.net.*;
import java.awt.*;
import java.util.*;
public class ClientApplet extends Applet {
public void init() {
Socket s = null;
try {
//s = new Socket(getParameter("host"), Integer.valueOf(getParameter("port")));
s = new Socket("localhost", 4444);
InputStream in = s.getInputStream();
int buf = -1;
while ((buf = in.read()) != '.') {
System.out.print((char)buf);
}
}catch(Exception e) {
e.printStrackTrace();
}
finally {
try {
s.close();
} catch(IOException e)
{ }
}
}
}
这是怎么回事?
I'm making a TCP Client in Applet mode and I get this strange error...
C:\Users\Dan\Documents\DanJavaGen\ClientApplet.java:20: cannot find symbol
symbol : method printStrackTrace()
location: class java.lang.Exception
e.printStrackTrace();
^
1 error
Tool completed with exit code 1
teh code:
import java.io.*;
import java.applet.Applet;
import java.net.*;
import java.awt.*;
import java.util.*;
public class ClientApplet extends Applet {
public void init() {
Socket s = null;
try {
//s = new Socket(getParameter("host"), Integer.valueOf(getParameter("port")));
s = new Socket("localhost", 4444);
InputStream in = s.getInputStream();
int buf = -1;
while ((buf = in.read()) != '.') {
System.out.print((char)buf);
}
}catch(Exception e) {
e.printStrackTrace();
}
finally {
try {
s.close();
} catch(IOException e)
{ }
}
}
}
What's the deal?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
尝试 printStackTrace 而不是 printStrackTrace (那里有一个额外的 r )
try printStackTrace instead of printStrackTrace (you have an extra r in there)
将 /
printStrackTrace
/ 替换为 /printStackTrace
/ (提示删除 Strack 中的 r )对于将来的错误,我会告诉您如何阅读此消息:
找不到符号:意味着您尝试使用的东西不存在,它可能是一个类、一个变量或类似的方法。
symbol :方法 printStrackTrace()** :它告诉您有问题的符号是什么,在本例中是一个名为
printStrackTrace
location 的方法,该符号在哪里符号假设是,在这种情况下,应该具有该方法的类是 java.lang.Exception ,它属于 java 核心类。
这会告诉您您所写的内容未被找到。应该给你一个很好的背景。大多数情况下,会包含发生错误的行,因此您可以知道哪个文件和行号。
我希望这对您以后的错误有所帮助。
replace: /
printStrackTrace
/ with /printStackTrace
/ ( hint drop the r in Strack )For future error, I'll tell you how to read this messages:
Cannot find symbol : Means, that something you're trying to use doesn't exists, it could be a class , a variable or like in this case, a method.
symbol : method printStrackTrace()** : It tells you what the problematic symbol is, in this case a method named
printStrackTrace
location where is that symbol suppose to be, in this case the class that should have the method is
java.lang.Exception
which belong to the java core classes.That tells you what was what you write that wasn't found. Should give you a good context. Most of the times the line where the error happen is included , so you can know what file and line number.
I hope this help you for future errors.
你拼错了 printStackTrace
You misspelled printStackTrace
e.printStackTrace 如果您只想要消息,则使用
System.out.println(e.getMessage());
e.printStackTrace and if uwant only message then use
System.out.println(e.getMessage());