开发者

The constructor Session(String,int) is not visible

开发者 https://www.devze.com 2023-03-23 23:18 出处:网络
I hav开发者_如何学Ce a jar that contains a class file Session.class. I did a import of all the jar and this class that I want to use. In my code as below:

I hav开发者_如何学Ce a jar that contains a class file Session.class. I did a import of all the jar and this class that I want to use. In my code as below:

public AgentInfo[] getInfo(){
    try {   
        session = new Session(host,port);
    }
}

Here I am getting error

 The constructor Session(String,int) is not visible


That suggests that the Session(String, int) constructor isn't public. For example, it might be declared like this:

Session(String host, int port)

instead of

public Session(String host, int port)

(It might be protected or even final, of course.)

If you can change Session and want to, you can make the constructor public. If you can't change it (e.g. it's a 3rd party class) you should look at what constructors are available, and also check for static methods returning Session, factory classes (e.g. SessionFactory) etc. Generally the documentation is a good start to find out how you're meant to get hold of an instance of a class :)


Very likely the constructor is private or protected or package access only. Are you sure you need to use that class? There might be derived classes that are better suited (or the class is supposed to be extended)


constructor probably is not public, if you have the source make it public or use some other constructor. oor if there is no visible constructor there is some factory for creating instances


Since you have access to the class file inside the zip file, view it in your IDE or run javap on it.

Chances are there is a static factory method returning session objects somewhere in that class or in a related class. This is common in cases where there are many types of sessions available.

0

精彩评论

暂无评论...
验证码 换一张
取 消