Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to override a loop fetching messages in a method
    primarykey
    data
    text
    <p>I have a Bluetooth server receiving data from a client, a mobile phone. The code I'm using looks the following</p> <pre><code>@Override public void run() { try { this.localDevice = LocalDevice.getLocalDevice(); this.localDevice.setDiscoverable(DiscoveryAgent.GIAC); this.server = (StreamConnectionNotifier) Connector.open(URL); while(true) { if(this.connection == null) { this.connection = this.server.acceptAndOpen(); System.out.println("INFO: Bluetooth client connected"); BufferedReader reader = new BufferedReader(new InputStreamReader(connection.openInputStream())); this.writer = new BufferedWriter(new OutputStreamWriter(connection.openOutputStream())); String line; while((line = reader.readLine()) != null) { if(line.equals("--#do:disconnect")) { break; } System.out.println("INFO: Received from Bluetooth: " + line); } System.out.println("INFO: Client disconnected"); } } } catch(BluetoothStateException ex) { ex.printStackTrace(); } catch(IOException ex) { ex.printStackTrace(); } } </code></pre> <p>As you can see, I have an infinitive loop receiving messages until it is told to stop. At the moment the loop receives all the messages. There is a problem with that. The class where the code is used is a model class in MVC. In the class I also have a method called <code>getContacts()</code>. It is used to receive contacts from the phone over Bluetooth. The phone is told to send the contacts when the server sends <code>--#do:getcontacts</code>. </p> <p>What I need to do is to get the contacts in an ArrayList in the <code>getContacts()</code> method and return it as the return value of the method so that the controller can handle the contacts. </p> <pre><code>public ArrayList&lt;Contact&gt; getContacts() { ArrayList&lt;Contact&gt; contacts = new ArrayList&lt;&gt;(); // How do I get the contacts in the ArrayList? return contacts; } </code></pre>
    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.
 

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