Java SSLSocket error: cannot be referenced from non-static context -


i struggling see wrong in here (part of class):

public class network implements runnable {         private static network cachedinstance;      private static boolean connected;      //private socket clientsocket;     private sslsocket clientsocket;     private printwriter out;     private bufferedreader in;      private map<string, syncobject> waitforserver;      private network(final string hostname, final int port) {         try {             socket basesocket = new socket();             basesocket.connect(new inetsocketaddress(hostname, port), config.timeout);             clientsocket = (sslsocket)sslsocketfactory.createsocket(basesocket, hostname, port, true);             clientsocket.starthandshake();             out = new printwriter(clientsocket.getoutputstream(), true);                  in = new bufferedreader(new inputstreamreader(clientsocket.getinputstream()));             connected = true;         } catch (ioexception ex) {              connected = false;         }          waitforserver = new hashmap<>();     } 

i error:

c:\users\frank\dropbox\netbeansprojects\tradingcardgame\src\network\network.java:47: error: non-static method createsocket(socket,string,int,boolean) cannot referenced static context         clientsocket = (sslsocket)sslsocketfactory.createsocket(basesocket, hostname, port, true); 

how being in static context?

regards.

sslsocketfactory.createsocket an instance method. means instance of sslsocketfactory class should created before 1 able invoke createsocket method on it.

you may try this

socketfactory sslsocketfactory = sslsocketfactory.getdefault(); clientsocket = (sslsocket) sslsocketfactory.createsocket(basesocket, hostname, port, true); 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -