Search code examples
javajavac

Javac error: Cannot find Symbol


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);
}

Solution

  • 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.