java - 在可序列化编程中收到错误 “cannot find symbol”

标签 java compiler-errors

我收到此错误:

Error:(5, 9) java: cannot find symbol
  symbol:   class Employee
  location: class Student
Error:(5, 24) java: cannot find symbol
  symbol:   class Employee
  location: class Student

嗨,我正在用Java编写一个可序列化的程序,但这给了我这个错误,请您解决一下并告诉我这是什么问题吗?

帮助将不胜感激!

这是我的源代码:
import java.io.*;

public class Student{
    public static void main(String[] args) throws Exception{
        Employee e=new Employee(221, "My name is Rajendra Arora");

        FileOutputStream fout=new FileOutputStream("D://raj1.txt");
        ObjectOutputStream out=new ObjectOutputStream(fout);

        out.writeObject(e);
        out.flush();

        System.out.println("Success....");
    }
}

最佳答案

确保Java文件都在同一目录中

例如:

myDirectory/Employee.java
myDirectory/Student.java

关于java - 在可序列化编程中收到错误 “cannot find symbol”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23367965/

相关文章:

compiler-errors - Eiffel :or and and and 中的本地声明编译失败

compiler-errors - 闭包——移动值的使用

c++ - 为什么该程序给出错误: to_string is not a member of std. Why?

java - 在两个构造函数中初始化最终变量

java - session 超时后,Spring Security 不会重定向到上次请求的页面登录

java - 如何避免或重命名 jaxb 中的键和条目标签?

java - 通过流将带有列表的列表对象转换为 Java 8 中的映射

java - Hashicorp Nomad 上的 Quarkus

c++ - 语法错误 "does not name a type"

在 Visual Studio Code 中进行 C 编译