Cannot make a static reference to the non-static method setupServer(int) from the type TCPServer
时间: 2024-03-25 18:36:08 浏览: 51
这个错误是因为你在尝试从静态上下文中访问非静态方法setupServer(int)。如果你想要在静态方法中使用非静态方法,你需要首先创建一个类的实例,然后通过该实例来调用非静态方法。例如:
```
TCPServer server = new TCPServer();
server.setupServer(port);
```
这样就可以在静态上下文中调用非静态方法了。
相关问题
Cannot make a static reference to the non-static method login() from the type yGym
This error message indicates that you are trying to call a non-static method from a static context. In Java, non-static methods belong to an instance of a class, whereas static methods belong to the class itself.
To resolve this error, you need to either make the method static or create an instance of the class and call the method on that instance.
If you want to make the method static, you can add the "static" keyword to the method signature. For example:
```java
public static void login() {
// method implementation
}
```
Alternatively, if you want to call a non-static method, you need to first create an instance of the class and then call the method on that instance. For example:
```java
yGym gym = new yGym();
gym.login();
```
I hope this helps to resolve your error!
Cannot make a static reference to the non-static method connServerDemo(String, int) from the type TCPClient
这个错误提示是说你不能通过类名直接调用一个非静态方法,因为非静态方法是需要实例化对象后才能使用的。你需要先创建一个 `TCPClient` 对象,然后通过这个对象来调用 `connServerDemo(String, int)` 方法。示例代码如下:
```
TCPClient client = new TCPClient();
client.connServerDemo("localhost", 8080);
```
这样就可以避免这个错误了。
阅读全文