Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Java cannot find my constructor?

Well, maybe it is a stupid question, but I cannot resolve this problem.

In my ServiceBrowser class I have this line:

ServiceResolver serviceResolver = new ServiceResolver(ifIndex, serviceName, regType, domain);

And compiler complains about it. It says:

cannot find symbol
symbol : constructor ServiceResolver(int,java.lang.String,java.lang.String,java.lang.String)

This is strange, because I do have a constructor in the ServiceResolver:

public void ServiceResolver(int ifIndex, String serviceName, String regType, String domain) {
        this.ifIndex = ifIndex;
        this.serviceName = serviceName;
        this.regType = regType;
        this.domain = domain;
    }

ADDED: I removed void from the constructor and it works! Why?

like image 683
Roman Avatar asked Mar 16 '10 14:03

Roman


2 Answers

delete void from signature

public ServiceResolver(int ifIndex, String serviceName, String regType, String domain) {
        this.ifIndex = ifIndex;
        this.serviceName = serviceName;
        this.regType = regType;
        this.domain = domain;
    }
like image 85
Roman Avatar answered Sep 27 '22 23:09

Roman


You have defined a method, not a constructor.

Remove the void

like image 21
Bozho Avatar answered Sep 28 '22 00:09

Bozho