Android run() method in Timer Task is not executing
<p><code>onCreate()</code> code starting the <code>TimerTask</code>:</p>

<pre><code>@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
Log.e(LOG_TAG, "Start Repeat Timer");
    TimerTask task = new RepeatingTask();
    Timer timer = new Timer();
    timer.scheduleAtFixedRate(task, 0, 3000);
    Log.e(LOG_TAG, "Started Repeat Timer");
}
</code></pre>

<p>Timer Task Code: </p>

<pre><code>public class RepeatingTask extends TimerTask {
     //private int len = 0; 
     //private byte[] input = new byte[len];

     public RepeatingTask() {
            Log.e(LOG_TAG, "In RepeatingTask()");
            Log.e(LOG_TAG, "Before inputJSON String");

            String hello = "hello world";
            //String inputJSON = getStringFromBuffer(new InputStreamReader(socket.getInputStream()));
            try {
                    inputJSON = ConvertByteArrayToString(readBytes(inputStr));
                    sendBytes(ConvertStringToByteArray(inputJSON), 0, ConvertStringToByteArray(inputJSON).length);
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            //Convert 
            Log.e(LOG_TAG, "After inputJSON String:" + inputJSON); 


         //LOOK HERE FIRST  
         //inputJSON is what is received back from the server - Take the inputJSON 
         //String and use regular expressions HERE to remove all the other characters in the 
         //string except the payload JSON.
         //refreshViewModels(inputJSON);
     }

     @Override
     public void run() { 
          /*try {
              Log.e(LOG_TAG, "IN REPEATINGTHREAD-INPUTJSON");
              //outputstrwr.write(outputJSONserv);  //UNCOMMENT IF NEED TO SEND DATA TO GET JSON BACK
              //inputJSON = ConvertByteArrayToString(getBytesFromInputStream(inputStr));
              inputJSON = ConvertByteArrayToString(getFileBytes(inputStr));
          } catch (IOException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }

          Log.e(LOG_TAG, "IN REPEATINGTHREAD-INPUTJSON2:" + inputJSON);
          refreshViewModels(inputJSON);*/

      try {
          Log.e(LOG_TAG, "IN REPEATINGTHREAD-INPUTJSON");
          //outputstrwr.write(outputJSONserv);  //UNCOMMENT IF NEED TO SEND DATA TO GET JSON BACK
          //byte[] = myByteArray = readBytes(inputStr);
          sendBytes(ConvertStringToByteArray(outputJSONserv), 0, ConvertStringToByteArray(outputJSONserv).length);
          //sendBytes(myByteArray, 0, myByteArray.length);
          Log.e(LOG_TAG, "AFTER SENDING DATA");
          //inputJSON = ConvertByteArrayToString(getBytesFromInputStream(inputStr));
                  inputJSON = ConvertByteArrayToString(readBytes(inputStr));
                  Log.e(LOG_TAG, "IN REPEATINGTHREAD-INPUTJSON2:" + inputJSON);
          } 
      catch (IOException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
          }

      Log.e(LOG_TAG, "IN REPEATINGTHREAD-INPUTJSON3:" + inputJSON);
      refreshViewModels(inputJSON); 
     }
}
</code></pre>

<p>inputStr is an <code>InputStream</code> used to read the bytes and convert them into a string.  </p>

<p><code>ConvertByteArrayToString()</code> just converts the byte array to <code>String</code> &amp; <code>ConvertStringToByteArray()</code> converts a <code>String</code> into a <code>Byte[]</code> so that the data can be sent using <code>sendBytes(byte[], int, int)</code>.</p>

<p>I'm trying to figure out why my code gets stuck in this try/catch statement without any exceptions being thrown:</p>

<pre><code>try {
                    inputJSON = ConvertByteArrayToString(readBytes(inputStr));
                    sendBytes(ConvertStringToByteArray(inputJSON), 0, ConvertStringToByteArray(inputJSON).length);
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
</code></pre>

<p>Here is my <code>sendBytes()</code> method:</p>

<pre><code> public void sendBytes(byte[] myByteArray, int start, int len) throws IOException {
        if (len &lt; 0)
            throw new IllegalArgumentException("Negative length not allowed");
        if (start &lt; 0 || start &gt;= myByteArray.length)
            throw new IndexOutOfBoundsException("Out of bounds: " + start);
        // Other checks if needed.

        // May be better to save the streams in the support class;
        // just like the socket variable.
        OutputStream out = socket.getOutputStream(); 
        DataOutputStream dos = new DataOutputStream(out);

        dos.writeInt(len);
        if (len &gt; 0) {
            dos.write(myByteArray, start, len);
        }
    }
</code></pre>

<p>Here is the <code>getPayloadStr()</code> method: </p>

<pre><code>    public String getPayloadStr(String profileString) {
        Log.e("LOG_TAG", "Profile Str:"+profileString);
        Pattern pattern = Pattern.compile(".*?payload\":(.*)\\}");

        Log.e("LOG_TAG", "I got here 1");
        Matcher matcher = pattern.matcher(profileString);
        Log.e("LOG_TAG", "I got here 12");
        //Matcher m = responseCodePattern.matcher(firstHeader);
        matcher.matches();
        matcher.groupCount();
        //matcher.group(0);
        Log.e("LOG_TAG", "I got here 2"+matcher.group(1));
        return matcher.group(1);
    }
</code></pre>

<p>Here is my <code>readBytes()</code> method:</p>

<pre><code>  public byte[] readBytes(InputStream in) throws IOException {
        // Again, probably better to store these objects references in the support class
        in = socket.getInputStream();
        DataInputStream dis = new DataInputStream(in);

        int len = dis.readInt();
        byte[] data = new byte[len];
        if (len &gt; 0) {
            dis.readFully(data);
        }
        return data;
    }
</code></pre>

<p>Any help or pointers in the right direction would be appreciated.  Any help via chat would be greatly appreciated too.  Whole file could be posted or viewed in chat session if needed.</p>
