Note that there are some explanatory texts on larger screens.

plurals
  1. POforce close when try to call a class that implements a Client Thread
    primarykey
    data
    text
    <p>I have a client-sever app on android,both running on the same machine. In the first activity of my client app I try to call client class which should connect to the server application,but I get force close.</p> <p>This is how I call the client class in the first activity of my app:</p> <pre><code>Thread cThread=new Thread(new ClientThread()); cThread.start(); </code></pre> <p>and here is my client class:</p> <pre><code>public class ClientThread implements Runnable{ private Handler handler=new Handler(); Socket socket; private TextView clientState; public void run() { try { InetAddress serverAddr=InetAddress.getByName("10.0.2.2"); handler.post(new Runnable(){ public void run(){ clientState.setText(" try to connect!"); } }); socket=new Socket(serverAddr, 8080); //connected=true; handler.post(new Runnable(){ public void run(){ clientState.setText("Connected!"); } }); } catch(Exception e){ handler.post(new Runnable(){ public void run(){ clientState.setText("Error"); } }); e.printStackTrace(); } } protected void onStop() { super.onStop(); try { // make sure you close the socket upon exiting //out.close(); socket.close(); } catch (IOException e) { e.printStackTrace(); } } } </code></pre> <p>Can someone tell what is wrong or at least give me an ideea. One thing that I should say is that my client works fine-it connects to the server,when the client class is integrated in my first activity(I mean,initially I had no client class was all in the first activity...and it worked fine). I'm here for further details! Thank u in advance!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload