Reputation: 2056
Receiving this error to which most results say Define the constructor, homeboy
. Any insights into what error I am making because I thought it is defined in my class. I'm pretty new to java, don't shred me if it's obvious.
Error: constructor KServer in class KServer cannot be applied to given types;
KServer server = new KServer(port);
required: no arguments
found: int
reason: actual and formal argument lists differ in length
1 error
KServer.java
public class KServer {
private int port;
//isn't this the constructor defined?
public void KServer(int PORT) {
port = PORT;
}
public void Run() {...}
}
KServ.java
public class KServ {
public static void main(String[] args) {
if (args.length != 1) {
System.err.println("Usage: java KServ <port number>");
System.exit(1);
}
int port = Integer.parseInt(args[0]);
KServer server = new KServer(port);
server.Run();
}
}
Upvotes: 0
Views: 123
Reputation: 18923
Remove the word void from the constructor definition :
public KServer(int PORT) {
port = PORT;
}
For more details on how to write constructors you can look here.
Upvotes: 3
Reputation: 7403
No return type for a constructor, otherwise you define a method.
public KServer(int PORT) {
port = PORT;
}
Upvotes: 2