Error with socket tcp on android

Asked

Viewed 19 times

1

I’m having a null error, I no longer know what I do, I’m using socket tcp in java in android studio, I already got the permission in the manifest, before I gave wrong permission denied, now the null error, and like I made this same code only using terminal, and it worked, only with the android studio q of the wrong

the code is this one

tn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Socket client;
            try {
                client = new Socket("10.0.1.138", 2000);
                while (true) {
                    Toast.makeText(getApplicationContext(), "Enviado para 10.0.1.138", Toast.LENGTH_LONG).show();
                    client.close();
                }
            }catch (Exception e){
                Toast.makeText(getApplicationContext(), "Ocorreu um erro:" + e.getMessage(), Toast.LENGTH_LONG).show();
            }

        }
    });
  • How is the manifest in the network part?

  • Now it must be giving network operation error in the main thread. It would have to do in a thread in the background.

  • Friends, I ended up losing the code that I was doing, I had to do a formatting on my hard drive, I appreciate your help, but I think it was not thread error, since before I did in pure java a code equal only that on console, I believe it would be some restriction of

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.