title: Separate a string with space
body: <p>I've seen various methods to split a string. I've tryed with both  from <a href="https://stackoverflow.com/questions/3732790/android-split-string">this</a> post. </p>
  
  <p>I'm trying to read and split the next string: <code>{2b 00 00}</code></p>
  
  <p>I see that the most common case is to split a message separated by ":", but in this case, my message is separated by spaces.</p>
  
  <p>Trying both ways, with the regular <code>split()</code> function or with the <code>StringTokenizer</code> I'm getting a "nullpointerexception" that I supose that is cause because of the space:</p>
  
  <pre><code>private String splitReceivedString(String s) {
      String[] separated = s.split(" ");
      return separated[1];
  }
  </code></pre>
  
  <p>How could I get the values of this kind of string?</p>
  
  <p><strong>ADDED CODE WITH THE POSSIBLE PROBLEM</strong></p>
  
  <p>After checking some of your answers, I do realize that the problem comes from the bluetooth inputstream. I'm getting null values from it. So, here is the code that I'm using to receive the messages:</p>
  
  <p>The code is almost the same than the bluetoothChat example. But it is modified to adapt to my program, so may I have something wrong.</p>
  
  <p>I've got an MCU wich returns me this String <code>{2b 00 00}</code> when I send to it another String. I think that this is done in the <code>connectedThread</code>:</p>
  
  <pre><code>public class ConnectedThread extends Thread {
  
     public void run() {
      byte[] buffer = new byte[1024];  // buffer store for the stream
      int bytes; // bytes returned from read()
  
      /**Keep listening to the InputStream until an exception occurs*/
      while (true) {
          try {
              /**Read from the InputStream*/
              bytes = GlobalVar.mmInStream.read(buffer);
  
              /**Send the obtained bytes to the UI activity*/
              GlobalVar.mHandler.obtainMessage(GlobalVar.MESSAGE_READ, bytes, -1, buffer).sendToTarget();
  </code></pre>
  
  <p>So, this is sending me the string to the handler function in the main activity:</p>
  
  <pre><code>    public final Handler mHandler = new Handler() {
      @Override
      public void handleMessage(Message msg) {
          switch (msg.what) {
              case GlobalVar.MESSAGE_STATE_CHANGE:
                  //The code here is irelevant
              case  GlobalVar.MESSAGE_WRITE:
                  byte[] writeBuf = (byte[]) msg.obj;
                  /**construct a string from the buffer*/
                  String writeMessage = new String(writeBuf);
                  GlobalVar.mCommunicationArrayAdapter.add(writeMessage);
                  break;
              case  GlobalVar.MESSAGE_READ:
                  byte[] readBuf = (byte[]) msg.obj;
                  /**construct a string from the valid bytes in the buffer*/
                  String readMessage = new String(readBuf);
                  GlobalVar.mCommunicationArrayAdapter.add(readMessage);
                  GlobalVar.readString = readMessage;                    
                  break;
  </code></pre>
  
  <p>Then, the variable <code>GlobalVar.readString</code> is the one that I'm getting in the split function:</p>
  
  <pre><code>    private String splitReceivedString (String s) {
  
          String[] separated = s.split(" ");
          return separated[1];
      }
  
      receive1 = splitReceivedString (GlobalVar.readString);
  </code></pre>
  
  <p>So, the thing is that it isn't reading right the received string, and I don't know how to fix it.</p>