简体   繁体   中英

Java cannot find symbol

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?

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

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.

您拼写了printStackTrace

e.printStackTrace and if uwant only message then use

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM