1

I'm using Socket Cluster and I (here the link enter link description here) have an OAuth app. So I'm getting nullPointerException in socket.connect() method. Here the syntax.

private String url = "http://There's my Ip and port";
private Socket socket;

public void connect(final String token) {
    Thread thread = new Thread(new Runnable() {
        @Override
        public void run() {
            socket = new Socket(url);
            socket.setAuthToken(token);
            socket.connect();

            if (socket.isconnected()) {
                Toast.makeText(act, "Socket connected successfully", Toast.LENGTH_SHORT).show();
            }
        }
    });

    thread.start();

}

You see the token in constructor? I'm calling this method in class where I'm doing the retrofit call, and when I got the access token, I'm giving it there. In socket.connect() it gives nullPointerException.

Hayk Mkrtchyan
  • 2,835
  • 3
  • 19
  • 61
  • Possible duplicate of [Unfortunately MyApp has stopped. How can I solve this?](https://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this) – Zoe Jun 08 '19 at 19:43

1 Answers1

0

Do you have the Internet Permission in manifest?

    <uses-permission android:name="android.permission.INTERNET" />