I had programmed several programs and I had compiled some of them, but know I have programmed a Chat messenger. And when I compile the Server or the Client I always get an error from javac. "error: cannot find symbol". And by both the error is at the constructor of other class how should construct there. example:
Chat.java:11 error: cannot find symbol
Frame frm = new Frame();
^
Symbol: class Frame
location: class Chat
Chat.java:11 error: cannot find symbol
Frame frm = new Frame();
^
Symbol: class Frame
location: class Chat
MAIN
package main;
public class Chat {
public static void main(String args[]){
Frame frm = new Frame();
frm.setLayout(null);
frm.setVisible(true);
frm.setSize(800, 600);
frm.setResizable(false);
// a loop who wait for an true boolean
frm.abfrage();
while(true){
frm.readChat();
}
}
}
FRAME Class without Functions(only Constructor)
package main;
//action + windowlistener + event import;
//Inputreader,writer,reader and IOException import;
//socket import + exception;
//.. there are some Javax.swing imports;
public class Frame extends JFrame {
Client client;
JPanel textPanel;
static boolean start;
static JTextArea messengerText;
JTextField writenText;
JTextField portInfo;
JTextField hostInfo;
JButton senden;
JButton connect;
public String writenString;
public String chatString;
int port;
String adress;
public Frame(){
super("Chat by lionlak");
// this.client = client;
client = new Client("localhost",5483);
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
//Deklarationen
start = false;
writenString = "Hallo vom Client";
chatString = "Chat by lionlak";
//Konstruktoren
//JPanel
textPanel = new JPanel();
//JTextField
writenText = new JTextField();
portInfo = new JTextField();
hostInfo = new JTextField();
messengerText = new JTextArea();
//JButton
senden = new JButton("SENDEN");
connect = new JButton("Connect");
//Listener
senden.addActionListener(new actionListener());
connect.addActionListener(new actionListener());
addWindowListener(new windowHandler());
//Eigenschaften
//JPanel
textPanel.setLayout(null);
textPanel.setBounds(10,150,490,780);
//JTextField
portInfo.setBounds(120,10,100,40);
portInfo.setText("5483");
hostInfo.setBounds(10, 10, 100, 40);
hostInfo.setText("127.0.0.1");
messengerText.setBounds(0,0,380,290);
messengerText.setText(chatString);
writenText.setBounds(0, 310, 280, 100);
writenText.setText("Deine Nachricht!");
//JButton
senden.setBounds(290, 310, 100, 40);
connect.setBounds(230, 10, 100, 40);
//Add
textPanel.add(messengerText);
textPanel.add(writenText);
textPanel.add(senden);
add(hostInfo);
add(portInfo);
add(connect);
add(textPanel);
}
util. List class without declaring the corresponding import, therefore the cannot find symbol error occurs. Adding the missing import statement (line 4 in Fig. 4(b)) solves the problem.
In the above program, "Cannot find symbol" error will occur because “sum” is not declared. In order to solve the error, we need to define “int sum = n1+n2” before using the variable sum.
The “cannot find symbol” error comes up mainly when we try to use a variable that's not defined or declared in our program. When our code compiles, the compiler needs to verify all the identifiers we have. The error “cannot find symbol” means we're referring to something that the compiler doesn't know about.
When the Java is not installed in our system and we try to run Javac command, we get Javac command not found or Java is not Recognized. We can also get this error when Java is installed in our system but the path is not added to the system's environment variable. Javac command is used to compile our java program.
In your Chat.java you are referencing your own Frame.class which lies in the same package. So there is no need for an import.
But the Frame.class has to be accessible to the Compiler, either by adding it to the classpath of the compiler or better by compiling all of your java files in a single compile call. For example:
javac Frame.java Chat.java
One problem might be if the Frame.java has compilation errors that prevents it from compiling so that there is no Frame.class.
You need to add the following import line at the beginning of your file:
import java.awt.Frame;
Depending on your tastes, and if you use other classes in the java.awt
package, you may want to use this:
import java.awt.*;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With