title: StringIndexOutOfBoundsException caused by substring
body: <p>I received this crash report in my Google Play Console which I myself never experience.</p>
  
  <pre><code>java.lang.RuntimeException: 
    at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2505)
    at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2577)
    at android.app.ActivityThread.access$1000 (ActivityThread.java:164)
    at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1462)
    at android.os.Handler.dispatchMessage (Handler.java:102)
    at android.os.Looper.loop (Looper.java:160)
    at android.app.ActivityThread.main (ActivityThread.java:5541)
    at java.lang.reflect.Method.invoke (Method.java)
    at java.lang.reflect.Method.invoke (Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:964)
    at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:759)
  Caused by: java.lang.StringIndexOutOfBoundsException: 
    at java.lang.String.startEndAndLength (String.java:504)
    at java.lang.String.substring (String.java:1333)
    at .Word.onCreate (Word.java)
    at android.app.Activity.performCreate (Activity.java:6093)
    at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1106)
    at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2458)
    at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2577)
    at android.app.ActivityThread.access$1000 (ActivityThread.java:164)
    at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1462)
    at android.os.Handler.dispatchMessage (Handler.java:102)
    at android.os.Looper.loop (Looper.java:160)
    at android.app.ActivityThread.main (ActivityThread.java:5541)
    at java.lang.reflect.Method.invoke (Method.java)
    at java.lang.reflect.Method.invoke (Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:964)
    at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:759)
  </code></pre>
  
  <p>This crash report doesn't mention which line of my <code>Word.java</code> class is causing the problem. In my class, I use the following <code>substring</code> method.</p>
  
  <pre><code>definition = defn.substring(0, defn.indexOf("@"));
  sentence = rawMeaning.substring(rawMeaning.lastIndexOf('@') + 1);
  </code></pre>
  
  <p>Examples of my <code>defn</code> string are <code>test1@test2</code>, <code>test1@</code>. Every of my <code>defn</code> string string contains <code>@</code>. Some string contains character after <code>@</code>, some do not contains any character after <code>@</code>. My <code>rawMeaning</code> string share a similar format with my <code>defn</code> string.</p>
  
  <p>It is interesting that I received another crash report which give me similar error but it mentioned the error is caused my in app billing, <a href="https://stackoverflow.com/questions/49684499/stringindexoutofboundsexception-caused-by-in-app-billing-queryinventoryasync">StringIndexOutOfBoundsException caused by in app billing queryInventoryAsync</a></p>
  
  <p>How to solve this?</p>