Note that there are some explanatory texts on larger screens.

plurals
  1. POParse string with delimiter ";" (java)
    primarykey
    data
    text
    <p>I have a string = "1.515 53.11 612.1 95.1 ; 0 0 0 0" I'm tring to parse it via this code:</p> <pre><code>public class SendThread implements Runnable { public void run() { socket = null; BufferedReader in; while (true) { // Loop until connected to server while (socket == null){ try{ socket = new Socket ("192.168.137.1", 808); } catch (Exception e) { socket = null; //Log.d("Connection:", "Trying to connect..."); } try { Thread.sleep(30); } catch (Exception e) {} } // Get from the server try { in = new BufferedReader(new InputStreamReader(socket.getInputStream())); Log.d("Connection: ", "connected"); String line = null; while ((line = in.readLine()) != null) { Log.d("Socket:", line); NumberFormat nf = new DecimalFormat ("990,0"); String[] tokens = null; String[] tempData = null; String[] windData = null; try { tokens = line.split(";"); tempData = tokens[0].trim().split(" "); windData = tokens[1].trim().split(" "); } catch (Exception error) { Log.d("Parsing error:", error+""); } for (int i = 0; i &lt; currentTemp.length; i++) currentTemp[i] = (Double) nf.parse(tempData[i]); for (int i = 0; i &lt; currentWind.length; i++) currentWind[i] = (Double) nf.parse(windData[i]); //Toast.makeText(getApplicationContext(), "Received data:", duration) for (int i = 0; i &lt; currentTemp.length; i++){ Log.d("Converted data: currentTemp["+i+"] = ", currentTemp[i]+""); } for (int i = 0; i &lt; currentWind.length; i++){ Log.d("Converted data: currentWind["+i+"] = ", currentWind[i]+""); } } socket = null; Log.d("Connection: ", "lost."); } catch (Exception e) { socket = null; Log.d("Connection: ", "lost."); Log.d("Connection:", e+""); } } } } </code></pre> <p>Bad code :( But I don't know better way to hold the socket connection :)</p> <p>I always get "java.text.ParseException: Unparseable number". How to fix it?</p> <p>tokens, tempData, windData are String[]</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.
    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