Java找不到符号

发布于 2024-09-12 02:14:10 字数 883 浏览 1 评论 0原文

我正在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

浅忆 2024-09-19 02:14:10

尝试 printStackTrace 而不是 printStrackTrace (那里有一个额外的 r )

try printStackTrace instead of printStrackTrace (you have an extra r in there)

笨笨の傻瓜 2024-09-19 02:14:10

将 /printStrackTrace/ 替换为 /printStackTrace/ (提示删除 Strack 中的 r

对于将来的错误,我会告诉您如何阅读此消息:

cannot find symbol
symbol  : method printStrackTrace()
location: class java.lang.Exception
e.printStrackTrace();
 ^
1 error

找不到符号:意味着您尝试使用的东西不存在,它可能是一个类、一个变量或类似的方法。

symbol :方法 printStrackTrace()** :它告诉您有问题的符号是什么,在本例中是一个名为 printStrackTrace

location 的方法,该符号在哪里符号假设是,在这种情况下,应该具有该方法的类是 java.lang.Exception ,它属于 java 核心类。

e.printStrackTrace();
 ^
1 error

这会告诉您您所写的内容未被找到。应该给你一个很好的背景。大多数情况下,会包含发生错误的行,因此您可以知道哪个文件和行号。

我希望这对您以后的错误有所帮助。

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
symbol  : method printStrackTrace()
location: class java.lang.Exception
e.printStrackTrace();
 ^
1 error

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.

e.printStrackTrace();
 ^
1 error

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.

南巷近海 2024-09-19 02:14:10

你拼错了 printStackTrace

You misspelled printStackTrace

别低头,皇冠会掉 2024-09-19 02:14:10

e.printStackTrace 如果您只想要消息,则使用

System.out.println(e.getMessage());

e.printStackTrace and if uwant only message then use

System.out.println(e.getMessage());

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文