@ Override public boolean onCreateOptionsMenu (Menu menu) { / / Inflate the menu; this adds items to the action bar if it is present .getMenuInflater () inflate (R.menu.main, menu);. return true; }
@ Override public void run () { / / TODO Auto-generated method stub try { socket = new Socket (ip, 8000); in = new DataInputStream (socket.getInputStream ()); out = new DataOutputStream (socket.getOutputStream ()); } Catch (UnknownHostException e) { / / TODO Auto-generated catch block e.printStackTrace (); / / Toast.makeText (this, "host name could not be resolved into an IP address", Toast.LENGTH_SHORT); } Catch (IOException e) { / / TODO Auto-generated catch block e.printStackTrace (); } while (true) { try { recvtext = in.readUTF (); mHandler.sendMessage (mHandler.obtainMessage ()); } Catch (IOException e) { / / TODO Auto-generated catch block e.printStackTrace (); } } } Handler mHandler = new Handler () { public void handleMessage (Message msg) { recvmsg.append (recvtext); super.handleMessage (msg); } };
} Always Rom server, and point start button the program in a virtual machine error stop<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) -> Reply: Network operations in the sub-thread to do, not on the main UI thread. Reply:
The main thread in just declare and define the socket number of variables, the new thread to accept it, so not okay Reply:
Wrong, sorry Two suggestions: 1 The best debugging on a real machine. 2.3 edittext short pointer before using no judgment, easily lead to a null pointer exception. You look at the application hang is not the reason. Reply:
Network operations in the sub-thread to do, not on the main UI thread.
The main thread in just declare and define the socket number of variables, the new thread to accept it, so not okay
Wrong, sorry Two suggestions: 1 The best debugging on a real machine. 2.3 edittext short pointer before using no judgment, easily lead to a null pointer exception. You look at the application hang is not the reason.
Network operations in the sub-thread to do, not on the main UI thread.
The main thread in just declare and define the socket number of variables, the new thread to accept it, so not okay
Wrong, sorry Two suggestions: 1 The best debugging on a real machine. 2.3 edittext short pointer before using no judgment, easily lead to a null pointer exception. You look at the application hang is not the reason.
I'm just learning , also does not see Logcat, I would first try is not a null pointer problem Reply: Reply: debug will do Reply:
debug will do
less likely to debug, ipaddr filled after the IP address text box, click the start button, the program socket = new Socket (ip, 8000); execution unit anymore. Do not fill ipaddr text box, program execution to in = new DataInputStream (socket.getInputStream ()); do not go, socket is null Reply: Try udx agreement, http://www.goodudx.com/web/index.php/site/download/25, security desk Development Kit. Reply:
socket = new Socket (ip, 8000); in = new DataInputStream (socket.getInputStream ()); out = new DataOutputStream (socket.getOutputStream ());
This change socket = new Socket (); socket.connect (new InetSocketAddress (ip, 8000)); in = new DataInputStream (socket.getInputStream ()); out = new DataOutputStream (socket.getOutputStream ()); Then put this thread inside it. while (true) { try { recvtext = in.readUTF (); mHandler.sendMessage (mHandler.obtainMessage ()); } Catch (IOException e) { / / TODO Auto-generated catch block e.printStackTrace (); } This code has a loophole, if an exception that should exit the loop, reconnect socket
No comments:
Post a Comment