Android Java ArrayIndexOutOfBoundsException : <p>I have some TextView which set the text from value saved in <code>SharedPreferences</code>. The values are split as array using "@".</p>

<pre><code>SharedPreferences mark = getSharedPreferences(PREFS_NAME, 0);
        String savestock =  mark.getString("stock", null);
        if (savestock != null) {
            stock = savestock.split("@", -1);
            tvstrength.setText(stock[0]);
            tvavailable.setText(stock[1]);
            tvbrand.setText(stock[2]);
            tvbatch.setText(stock[3]);
            tvexp.setText(stock[4]);
            tvstrength2.setText(stock[5]);
            tvavailable2.setText(stock[6]);
            tvbrand2.setText(stock[7]);
            tvbatch2.setText(stock[8]);
            tvexp2.setText(stock[9]);
            }
</code></pre>

<p>This is how the <code>SharedPreferences</code> is saved:</p>

<pre><code>SharedPreferences mark = getSharedPreferences(PREFS_NAME, 0);
SharedPreferences.Editor editor = mark.edit();
editor.putString("stock", inStrength + "@" + inamt + "@" + inBrand + "@" + inBatch + "@" + inExp + 
inStrength2 + "@" + inamt2 + "@" + inBrand2 + "@" + inBatch2 + "@" + inExp2);
editor.commit();
</code></pre>

<p>However, I got the error <code>java.lang.ArrayIndexOutOfBoundsException: length=9; index=9</code>. The error is caused by <code>tvexp2.setText(stock[9]);</code></p>

<p>What mistake I made?</p>
