this is my class
public class mm {
public class MessageHandler {
public HashMap<String, Command> commandMap;
public MessageHandler() {
this.commandMap = new HashMap<>();
commandMap.put("init", new CreateOfferCommand());
commandMap.put("offer", new CreateAnswerCommand());
commandMap.put("answer", new SetRemoteSDPCommand());
commandMap.put("candidate", new AddIceCandidateCommand());
}
public Emitter.Listener onMessage = new Emitter.Listener() {
@Override
public void call(Object... args) {
JSONObject data = (JSONObject) args[0];
try {
String from = data.getString("from");
String type = data.getString("type");
JSONObject payload = null;
if(!type.equals("init")) {
payload = data.getJSONObject("payload");
}
// if peer is unknown, try to add him
if(!peers.containsKey(from)) {
// if MAX_PEER is reach, ignore the call
int endPoint = findEndPoint();
if(endPoint != MAX_PEER) {
Peer peer = addPeer(from, endPoint);
peer.pc.addStream(localMS);
commandMap.get(type).execute(from, payload);
}
} else {
commandMap.get(type).execute(from, payload);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
};
public Emitter.Listener onId = new Emitter.Listener() {
@Override
public void call(Object... args) {
String id = (String) args[0];
mListener.onCallReady(id);
}
};
public Emitter.Listener onCall = new Emitter.Listener() {
@Override
public void call(Object... args) {
String id = (String) args[0];
mListener.onCalling(id);
}
};
}
......................
.........
}
and when i call the inner class from another class its give me an enclosing class
mm.MessageHandler messageHandler = new mm.MessageHandler();
when i make inner class messageHandler a static the error gone but its shown anothe error inside inner class so can i call the inner class without make it static ?
asked Jun 19, 2016 at 16:06
Максим Зубков
6452 gold badges8 silver badges23 bronze badges
1 Answer 1
mm n = new mm();
mm.MessageHandler messageHandler = n.new MessageHandler();
or use static in your inner class
hope that's help
answered Jun 19, 2016 at 17:27
user5107123
Sign up to request clarification or add additional context in comments.
Comments
lang-java