'"java.lang.IndexOutOfBoundsException" error, app crashes when I'm fetching data from my database

I have a list of suppliers and the idea is that when I click one it opens a more detailed page with information such as URL, specialization, country etc.

Recently, i've been trying to open suppliers to the detailed page. Every time I try to do so my application crashes and I get the following error message:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.labarassi/com.example.labarassi.GUI.DetailActivity}: java.lang.IndexOutOfBoundsException: Index: 2, Size: 2 

And the error points out the following code:

private void getSelectedSupplier()
    {
        Intent previousIntent = getIntent();
        String parsedStringID = previousIntent.getStringExtra("id");
        selectedSupplier = SupplierPage.supplierList.get(Integer.parseInt(parsedStringID));
    }

If anyone has any idea as to why this is happening or what I could look for in my code it would be a great help (:



Solution 1:[1]

Not entirely sure but maybe it has something to do with parsedStringID number being returned not conforming to the correct index position (since indexes start at 0). Maybe try:

SupplierPage.supplierList.get(Integer.parseInt(parsedStringID) -1);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 lew