Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid NetowrkOnMainThreadException
    primarykey
    data
    text
    <p><em>Hi !!</em></p> <p>I try to build an Android Application to control the Ar drone. But i have a problem when i try to connect my device with the drone. I created a Thread to do a socket. But when i run it in the main activity i have a exception : <strong>android.os.NetworkOnMainThreadException</strong> .</p> <p>This is my code with my Thread in ThreadCmd class: </p> <pre><code>String commande=""; byte[] cmdToByte; String iPinString; InetAddress IpDrone; DatagramSocket clientSocket; Thread threadDecollage; TextView tv ; boolean etat; DatagramPacket sendPacketWithCmd; private byte[] ip = {(byte)192, (byte)168, (byte)1, (byte)1 }; boolean isRunning = true; private final static long TIME_SLEEP= 20; public void run() { try { IpDrone = InetAddress.getByAddress(ip); } catch (UnknownHostException e1) { e1.printStackTrace(); etat = false; } try { clientSocket = new DatagramSocket(); } catch (SocketException e) { e.printStackTrace(); etat = false; } while(isRunning){ runControl(); try { Thread.sleep(TIME_SLEEP); } catch (InterruptedException e) { e.printStackTrace(); } } } public void runControl(){ commande ="AT*REF=1,290717696&lt;LF&gt;AT*REF=2,290717952&lt;LF&gt;AT*REF=3,290717696&lt;LF&gt;"; cmdToByte = commande.getBytes(); try { sendPacketWithCmd = new DatagramPacket(cmdToByte,cmdToByte.length,IpDrone,5556); clientSocket.send(sendPacketWithCmd); } catch (IOException e) { e.printStackTrace(); etat = false; } etat = true; isRunning=false; } public boolean retourneetat(){ return etat; } </code></pre> <p>After in the main activity :</p> <pre><code> Threadcmd tc = new Threadcmd(); tc.run(); </code></pre> <p>I dont see my error so i ask to you if you can help me !! ( i don't forget the permission)</p> <p>ps: please excuse my english :)</p>
    singulars
    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