test
test

Reputation: 18198

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?

Upvotes: 1

Views: 3536

Answers (4)

Jay Thakkar
Jay Thakkar

Reputation: 719

e.printStackTrace and if uwant only message then use

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

Upvotes: 0

OscarRyz
OscarRyz

Reputation: 199294

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.

Upvotes: 3

jdigital
jdigital

Reputation: 12296

You misspelled printStackTrace

Upvotes: 1

superfell
superfell

Reputation: 19050

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

Upvotes: 3

Related Questions