StringOutOfBoundException in BluetoothChat Example
<p>In my application I'm using a slightly modified version of the class DeviceListActivity that comes from the BluetoothChat example. The code worked well on all the device i tested, but when i published the application i started to receive reports like this:</p>

<pre><code>java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.lang.String.substring(String.java:1555)
at sword.games.highnoonf.activities.DeviceListActivity$1.onItemClick(DeviceListActivity.java:18    0)
at android.widget.AdapterView.performItemClick(AdapterView.java:284)
at android.widget.ListView.performItemClick(ListView.java:3388)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:1738)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:143)
at android.app.ActivityThread.main(ActivityThread.java:5097)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)
</code></pre>

<p>The function that causes the exception is this:</p>

<pre><code>private OnItemClickListener mDeviceClickListener = new OnItemClickListener() {
    public void onItemClick(AdapterView&lt;?&gt; av, View v, int arg2, long arg3)       {         
        // Cancel discovery because it's costly and we're about to connect
        mBtAdapter.cancelDiscovery();

        // Get the device MAC address, which is the last 17 chars in the View
        String info = ((TextView) v).getText().toString();
        String address = info.substring(info.length() - 17);
        String devName = info.substring(0, info.length() - 17);

        // Create the result Intent and include the MAC address
        Intent intent = new Intent();
        intent.putExtra(EXTRA_DEVICE_ADDRESS, address);
        intent.putExtra("DEVICE_NAME", devName);

        // Set result and finish this Activity
        setResult(Activity.RESULT_OK, intent);
        finish();
    }
};
</code></pre>

<p>The rest of the code is almost identical to the DeviceListActivity example...
I hope someone can fix this or give me an explanation of why this happens...
Thank you...</p>

<p>Edit: The code is already checking that the name exists and the length of the MAC address are correct with those line (if somethings goes wrong the phone is not added and the user can't click on it):</p>

<pre><code>String name = device.getName();
String address = device.getAddress();

if(name == null) name = "Unknown";
else if (name.length() == 0) name = "Unknown";

if (address.length() == 17){
    mNewDevicesArrayAdapter.add(name + "\n" + address);
}
</code></pre>
