[英]Getting Error Exception in thread “main” java.lang.IllegalAccessError:
My Directory Structure is shown below : 我的目录结构如下所示:
ObjectPassing
|->student.txt
|->StudentAddress.java
|->StudentClient.java
|->StudentServer.java
|->StudentAddress.class
|->StudentClient.class
|->StudentServer.class
and i am getting error while running file StudentClient.java which contains instance of StudentAddress class.Server Started Successfully but client is not working properly. 并且我在运行文件StudentClient.java时出错,该文件包含StudentAddress类的实例。服务器已成功启动,但客户端无法正常工作。
Source Code : - 源代码 : -
import java.net.Socket;
import java.io.ObjectOutputStream;
public class StudentClient{
private String hostName;
private int portNumber;
private Socket client;
public StudentClient(String th,int tp){
this.hostName = th;
this.portNumber = tp;
try {
client = new Socket(hostName,portNumber);
ObjectOutputStream output = new ObjectOutputStream(client.getOutputStream());
StudentAddress data = new StudentAddress();
data.getData();
output.writeObject(data);
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
new StudentClient("localhost",8000);
}
}
All class StudentAddress,StudentServer,StudentClient are complied successfully.While Running StudentClient.java it show below error: 所有类StudentAddress,StudentServer,StudentClient均已成功编译。在运行StudentClient.java时,显示以下错误:
Command:javac StudentClient.java 命令:javac StudentClient.java
Exception in thread "main" java.lang.IllegalAccessError: class StudentClient tried to access method StudentAddress.<init>()V (StudentClient is in unnamed module of loader com.sun.tools.javac.launcher.Main$MemoryClassLoader @5e57643e; StudentAddress is in unnamed module of loader 'app')
at StudentClient.<init>(StudentClient.java:18)
at StudentClient.main(StudentClient.java:27)
Oh wait, you are running javac from ObjectPassing
directory, that's the issue. 哦,等等,您正在从
ObjectPassing
目录运行javac,这就是问题所在。 Run it from Networking
directory. 从
Networking
目录中运行它。
When you mention package
keyword, javac
will expect a directory under the current directory from where you run it to contain the directory or directories for the package name mentioned. 当您提到
package
关键字时, javac
将在您运行它的当前目录下期望一个目录,其中包含提到的软件包名称的一个或多个目录。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.