Skip to content Skip to sidebar Skip to footer

Android Indexoutofboundsexception: Index: 1, Size: 1

I'm new to using SQLite on Android and I have some error here. I have this app: http://imgur.com/gallery/The7Q With the code below I can click on the save button and on the first i

Solution 1:

Your error occurs when the coding can't reach the specific index. You may check on this thread.

IndexOutOfBound exception means you've got a problem because you're trying to access an index which doesn't exist or is empty (not null). For example if you've got an array with only two elements, so it only has index 0 and 1, and you try to access index 2 you'll get an IndexOutOfBoundException because index 2 doesn't exist. If you make an array of 10 elements and only fill 5, indexes 4-9 will be empty, accessing those might cause an IndexOutOfBoundException.

Here's a possible workaround on how to fix this:

If you're using an IDE it might help you to debug the problem by removing the throws statements. Throws statements "pass the buck" when it comes to exceptions, you're not actually handling exceptions by using throws. Try-catch statements handle exceptions much better because they narrow down the area where the problem is (because they 'test' the code within the try brackets.

Throws have their place, but for debugging try-catch can be much more helpful.

Additional references:

Post a Comment for "Android Indexoutofboundsexception: Index: 1, Size: 1"