I apologize in advance for a possible Nubian question, new to java) and there are no normal tutorials on socket.io. With Google, I tried to start learning and it seemed to work out something (the application at least starts xD), but when I press the button on the form and Connect is done, then crash with an error

 java.lang.NullPointerException: Attempt to invoke virtual method 'io.socket.client.Socket io.socket.client.Socket.connect()' on a null object reference 

That's what happened) can you explain what is wrong?

 public class LoginActivity extends AppCompatActivity { private Socket mSocket; { try { mSocket = IO.socket("192.168.100.3:8080"); } catch (URISyntaxException e) {} }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); } public void Connect(View v){ mSocket.connect(); }; } 
  • An empty catch block is the cause of your difficulties. If you output an error in it, you will see that the variable was not initialized - Yuriy SPb
  • Thanks, it helped) the problem was that there was no http:// before the ip address - EvillNooB

1 answer 1

According to the commentary , after the error in the catch block was output to the console, it turned out that the address lacked a scheme, i.e. http:// . That was the mistake