title: Strange logcat ideas on how to solve it?
body: <p>I have this method that takes the first 16 characters by outpout obtained from the execution of the command "busybox"</p>
  
  <pre><code>public String busybox_v() throws IOException  {
  
          Process p =Runtime.getRuntime().exec("busybox");
          InputStream a = p.getInputStream();
          InputStreamReader read = new InputStreamReader(a);
          BufferedReader in = new BufferedReader(read);
          StringBuilder buffer = new StringBuilder();
  
          String line = null;
  
          try { 
  
              while ((line = in.readLine()) != null) {
                  buffer.append(line);
              }
  
          } finally {
              read.close();
              in.close();
          }
  
          if (buffer.length()&gt;=16)
          {
              String result = buffer.toString().substring(0, 15);
  
          }
          else
          {
  
          }
          String result = buffer.toString().substring(0, 15);
          return result; 
  </code></pre>
  
  <p>Before, I had this crash</p>
  
  <pre><code>java.lang.StringIndexOutOfBoundsException: length=0; regionStart=0; regionLength=15 
  at java.lang.String.startEndAndLength(String.java:583) at java.lang.String.substring(String.java:1464) 
  at com.MyPackage.MyApplicationName.Root.busybox_v(Root.java:98) 
  at com.MyPackage.MyApplicationName.PageFragment$1.onClick(PageFragment.java:101) 
  at android.view.View.performClick(View.java:4240) at android.view.View$PerformClick.run(View.java:17721) 
  at android.os.Handler.handleCallback(Handler.java:730) 
  at android.os.Handler.dispatchMessage(Handler.java:92) 
  at android.os.Looper.loop(Looper.java:137) 
  at android.app.ActivityThread.main(ActivityThread.java:5103) 
  at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:525) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737) 
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:110) 
  at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>The line 98 corresponds to the closing brace of the while, then thanks to the advice of you users to stack Overloflow I put a if-else that checks if the length is actually greater than or equal to 16 characters, not making crash the application. But with the current code the application crashes all the same because I have this code in another class</p>
  
  <pre><code>try {
  
  String myResult=root.busybox_v();  
  if(myResult!=null&amp;&amp;myResult.length()&gt;0) {
  
      TextView1.setText(Html.fromHtml(("&lt;b&gt;&lt;font color=\"#009900\"&gt;"+myResult+"&lt;/font&gt;&lt;/b&gt;")));
  
  
  }
  else {
  
  }
      } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
  }
  
  
  
              }
          );
  </code></pre>
  
  <p>Do you have ideas on how I can fix this?</p>